Compiling init scripts as C

Hello!
A while back, I read that Blice (owner of http://its.alrig.ht/) had converted their init scripts to C to help the computer boot faster.
Unfortunately, Blice's site seems to have disappeared, which is a shame since I'd like to read some of the information on his webpage.
Anywho, my question is: anybody here have experience in converting startup scripts to C?
I've rewritten the apache, ssh, and postfix startup scripts so far. I've put the code up on GitHub at http://github.com/ColinJones/binary-startup
Any thoughts?

I kind of like the idea myself. I would like to help with the development.
After rethinking a bit, I don't think the hardest part to develop is the actually code, the part that is going to be challenging is the build script. I mean, if it is going to be according to my original idea, the program code itself is going to be simple but to be able to have simple program code when parsing rc.conf it means that the build script has to be a bit more complex, otherwise it will mean that the program code itself has to parse rc.conf. Well, that means if the rc.conf is going to be parsed in the first place. I think it should be parsed during build time, it will be a bit like mkinitcpio but for the initscripts but that is of course in my opinion.
One of the first thing that needs to be done is probably do a prof-of-concept of a program + build script that can depending on the content of the config file build a program with different functionality. This is pretty much to simulate the DAEMONS array. A traditional way of doing this with statically linking is to including different files with the same interfaces and in case a functionality is not going to be present, use interface functions that are empty. This pretty much works when there isn't a lot of different functionality but I think there are to many possible DAEMONS to make this practical. I think a better way is to generate a config.h (or use a different name for the file) which contains a list of functional pointers to all the "modules" that should be included. In short, make the program aware of the function and include the file that contains the function to the linker and make the complete process dynamically.
I might look in this prof-of-concept during the weekend.
Last edited by PJ (2010-01-08 18:18:09)

Similar Messages

  • Some init script ideas

    I'm packaging GNUstep... again (this time from CVS), and it requires a certain shell script to be sourced by every shell.  That's easy enough for any user to do by modifying their .foorc and adding it in there, but I thought I would just throw a command in the postinstall to symlink the shell script to /etc/profile.d, so every login shell would automatically source it.
    That's all fine and dandy, but xterms by default aren't login shells, so anybody using an xterm would find themselves without a working GNUstep build environment unless they set xterm to be a login shell in their .Xdefaults.
    Change #1) Make xterms login shells by default in Arch's xfree86 distribution
    Now that xterms are all login shells, and we can expect a user's shell to be a login shell by default, why not add scripts to profile.d for the various self-contained distributions that live in /opt (like gnome, kde, java, etc.) that automatically set up the paths for those binaries.  At the moment, it appears you have to do this manually (I have not installed gnome or kde though, maybe those maintainers are doing this).
    Change #2) Have packages that live in /opt add a script to profile.d setting up the paths and environment necessary to use those packages.
    Thirdly, there's two daemons that need to be started for GNUstep when xfree86 starts (specifically gdnc and gpbs).  Once again, this is something that can easily be done by a user editing their .Xsession, but I'd rather automate it.  In the spirit of Arch's init script system, I think it would be wise to make an xinit.d directory (possibly in /etc, or more to the keeping of X's directory structure, in /etc/xinit.d), full of files that are run whenever X is started.  These could be enabled and disabled in rc.conf just like init scripts in rc.d currently are.
    Change #3) Add an xinit.d directory, in the spirit of rc.d and profile.d, full of items that are run whenever X is started.
    Perhaps some of this has already been done, or perhaps there are other solutions.  I just think these changes would be well in the spirit of Arch, and a boon to package maintainers.
    Please give me your feedback either here or by mailing me at [email protected]
    -- Michael Baehr

    sarah31 wrote:most if not all /opt package sets have profile.d scripts.  some may not think so but one has to log out then in to enable them.
    Good Looks like profile.d is being used for the right purpose.  I should've expected it would be  :oops:
    Xentac wrote:Ok... but what happens if I'm running blackbox?  I probably don't want gdnc and gpbs started when I start X, it'd make me cry.  How would xinit.d help with that?
    I don't see why it'd make you cry.  Let me explain what gdnc and gpbs are:
    GNUstep Distributed Notification Center
    Handles messaging and notification between GNUstep applications
    GNUstep Pasteboard Server
    Handles rich copy and paste between GNUstep applications
    Basically, none of these would impact whatever environment you'd be running, and only GNUstep apps would use them.  In fact, you wouldn't even realize they were running as they'd just be sitting in the background like the valiant daemons they are, waiting to be called into service for the holy emperor GNUstep  :twisted:
    And in any case, with the whole xinit.d idea, you should be able to just disable it with a ! if you don't like it
    I might as well throw in my last idea, which I forgot to write before.
    I've noticed people complaining about Pacman upgrades wiping their pacman.conf, which is a problem if you're using several people's TURs and other external repositories like I am.  Instead, I propose doing what APT has been doing in a recent version with its new sources.list.d layout... having one directory (pacman.repo.d or something of its ilk) storing files for each repository, and enabling and disabling them in pacman.conf the way you do in rc.conf (with a bang).  This would be especially nice because somebody could install a package called, for example, "pacman-TUR", and have a repo file for each TUR, and then be able to enable or disable them.  This package would be updated every time a new TUR was added or one was removed, thus enabling people to easily track the latest repository happenings, while still maintaining control over what repos they use.
    Just a thought.

  • Cannot launch vivado simulator 2015.1: behav/compile.bat' script "Please check that the file has the correct 'read/write/execute' permissions"

    Hi,
    I'm trying to run a verilog simulation using the vivado simulator 2015.1 on Windows 7.
    I get the following error when I attempt to launch simulation:    
    ERROR: [USF-XSim-62] 'compile' step failed with error(s) while executing 'D:/projects/axi/axi_test_system/axi_test_system.sim/sim_1/behav/compile.bat' script. Please check that the file has the correct 'read/write/execute' permissions and the Tcl console output for any other possible errors or warnings.
    The tcl console repeats the same message, "Please check that the file has the correct 'read/write/execute' permissions"
    I cannot find any problem with the permissions.  I believe that windows will always execute a .bat file.   Within the same project, I can run elaboration, synthesis and implementation without problems. 
    Any idea why the simulation compile script won't run?
    Thanks,
    Ed

    Hi,
    Thanks very much for your detailed reply. These were the right questions based upon what I told you.   
    However, I took the code home last night and ran it on my webpack 2014.2 release.   It still failed, but I got completely different error messages.   These messages correctly pointed me to an undeclared signal in my testbench. Once fixed, the compile worked and the simulator launched. 
    This morning, I fixed the signal name in my 2015.1 setup, and it also compiled and launched correctly. 
    So, the problem wasn't actually related to file permissions.  It seems like the 2015.1 error message may be broken compared to 2014.2.  
    I was running the Vivado GUI, clicking on "Simulate > Run Behavioral Simulation"
    Thanks again for your help. 
    Regards,
    Ed  
      

  • Init scripts

    It has been a while since I last posted, but I like arch.
    My question is regarding the init scripts used in arch.  Specifically, three common commands used in the init scipts, and they are "stat_fail","stat_done", and "add_daemon".
    Could some refer me a wiki, webpage or man page for them, and yes I see there definitions in /etc/rc.d/functions file.

    For example in add_daemon:
    add_daemon() {
            [ -d /var/run/daemons ] || mkdir -p /var/run/daemons
            touch /var/run/daemons/$1
    What is the variable $1 refer to?  I cannot see it defined anywhere else in the function or in the /etc/rc.d/functions script.  Could it be the function referred to in which /etc/rc.d/"script" is run; "script" being whatever init service that is started and stopped,  ie crond would be then touch /var/run/daemons/crond?
      For what it is worth I am just trying to improve my shell scripting skills.
    [/i]

  • Dhcpcd starting by wich init-script? [Solved]

    I have static ip on both eth devices.  These configured by netcfg: with if1 and if2 files in /etc/network.d/
    here they are:
    cat /etc/network.d/if1
    CONNECTION='ethernet'
    DESCRIPTION='ethernet connection to internet'
    INTERFACE='eth0'
    IP='static'
    ADDR='10.85.231.106'
    NETMASK='255.255.0.0'
    GATEWAY='10.85.231.65'
    DNS=('10.85.224.33')
    cat /etc/network.d/if1
    CONNECTION='ethernet'
    DESCRIPTION='ethernet connection to localnet'
    INTERFACE='eth1'
    IP='static'
    ADDR='192.168.225.222'
    NETMASK='255.255.255.0'
    But my resolve.conf sometimes is overwritten by dhcpcd.
    in /etc/rc.conf I don't have any property connected with net set except HOSTNAME="ramazotty" and NETWORK_PERSIST="no"
    my daemons are:
    DAEMONS=(hwclock syslog-ng network net-profiles sshd samba xinetd @cupsd dbus @netfs crond)
    Who in the world is starting dhcpcd?
    p.s. The parent is process 1:
    >ps -f `pidof dhcpcd`
    UID        PID  PPID  C STIME TTY      STAT   TIME CMD
    root       497     1  0 15:09 ?        Ss     0:00 dhcpcd -q
    Last edited by roginovicci (2012-10-26 09:16:04)

    FYI you don't need the network init script when you're using netcfg.
    This is not the answer you're looking for, just some useful information - unless you happen to be wrong about your rc.conf.

  • Synergyc as init script

    Greetings,
    I am trying to start synergyc as an init script so that it will work with slim, i copied the init script from the wiki, however, i get the error Fri Apr 13 10:16:02 2012: /usr/bin/xset:  unable to open display ""
    and the client never connects to the server.
    thanks!
    Adam

    If you're using slim, just put it in your .xinitrc, it's much easier and tends not to throw as many errors (at least for me, anyway).

  • [SOLVED] netatalk and postfix init scripts (not systemd)

    Hey, does anybody have an older version of Arch running somewhere?
    I'm looking for init scripts for netatalk and postfix that I've just re-built from ABS on an outdated Arch system. However, both packages offer systemd support these days and no love for dissidents like myself.
    They are probably very simple to write on one's own, but I just want to make sure I don't overlook some important trick.
    If someone could possibly post those either here or on dpaste.org or whatever paste service you love, I would be a very happy person lol
    Last edited by iliv (2013-12-01 14:17:00)

    netatalk is in the AUR https://aur.archlinux.org/packages/netatalk/
    postfix: https://projects.archlinux.org/svntogit … a3365f273e

  • Suggestion for init scripts

    I like the simplified sysvinit scripts that Arch uses, but I think the file locations could be improved a bit.  /etc should be reserved for configuration files only; when you put init scripts in there as well the /etc folder gets a little cluttered.
    Since we already have an rc.d folder anyway that contains some of the init stuff, why not put all rc scripts, settings, and so forth in the same rc.d folder?
    I'm probably not the smartest person to be talking about optimal naming conventions and file locations for the sysvinit stuff... I renamed my rc.conf to CONFIG.SYS and my rc.sysinit to AUTOEXEC.BAT

    tomk wrote:Could you clarify your suggestion? All the application init scripts are already in /etc/rc.d, and the system init scripts e.g. /etc/rc.sysinit, are in standard locations. The rest of /etc consists of system-wide application configs, and their locations are determined upstream.
    Also, iBertus is right.
    Well, I wasn't talking about the rest of /etc - specifically the init scripts (rc.single, rc.multi, etc.)  Alas, I'm unfamiliar with the bsd init process (or at least I was before this discussion).  Since one of the packages we install from base is sysvinit, I *assumed* (there I go again) it was indeed a SysV init process, only modified for Arch purposes.  That is, I thought y'all just arbitrarily decided to put rc.multi et al in /etc. and I was suggesting, as long as you're arbitrarily changing stuff around, why not keep all the rc. stuff together in /etc/rc.d.  Now that I know you're just conforming to bsd standards, my premise (that it was an arbitrary decision) is meaningless so I withdraw the suggestion and stand corrected.
    shining wrote:Seeing how much the rest of your post makes sense, I am not even sure if that's supposed to be a joke.
    Wow, I should have stayed back in newbie corner where there's no such thing as a stupid question!  It is a joke... and I was serious.  That is, I really did rename rc.conf to config.sys and rc.sysinit to autoexec.bat, but specifically *because* it's a joke, even if I'm the only one who will ever see it.  Kinda like the APPLE ][ logo I use for my Fluxbox wallpaper.
    Thanks for the explanations, ibertus and tomk... I obviously have a lot to learn about Arch (and *nix in general) before I'm ready to pitch in with meaningful suggestions!

  • WOL, init scripts and KDE

    Hello
    So, I may be confused with how init scripts are working, but in this case there is something I do not get.
    I am trying to be an energy efficient geek, so I decided to set-up a Wake On Lan (WOL) on my home server. The WOL itself is working fine, no issue on this side, but in order to have this working after each reboot, and according to the wiki, I have to add the following code to my rc.local file to set the WOL flag to my network interface.
    ethtool -s eth0 wol g
    And here is the problem : by default, my "server" starts a kde session after the boot. So my inititab is like that :
    ## Only one of the following two lines can be uncommented!
    # Boot to console
    # id:3:initdefault:
    # Boot to X11
    id:5:initdefault:
    # Example lines for starting a login manager
    #x:5:respawn:/usr/bin/xdm -nodaemon
    #x:5:respawn:/usr/sbin/gdm -nodaemon
    x:5:respawn:/usr/bin/kdm -nodaemon
    #x:5:respawn:/usr/bin/slim >/dev/null 2>&1
    With these settings, the WOL flag is not set correctly after the boot. Now, if I do not start kde, use a console login and change my inittab to :
    ## Only one of the following two lines can be uncommented!
    # Boot to console
    id:3:initdefault:
    # Boot to X11
    #id:5:initdefault:
    # Example lines for starting a login manager
    x:5:respawn:/usr/bin/xdm -nodaemon
    #x:5:respawn:/usr/sbin/gdm -nodaemon
    #x:5:respawn:/usr/bin/kdm -nodaemon
    #x:5:respawn:/usr/bin/slim >/dev/null 2>&1
    In this case, the command in rc.local is executed correctly and my WOL flag is set as I want. So, either kde overwrites the flag when it starts or the rc.local file is not executed.
    Anyone with a clue of what is going on and how to solve that ?
    Thanks !
    Last edited by Cobaltounet (2011-02-02 04:25:24)

    zenlord wrote:
    Since your problem is solved, it might be the right time to ask my question to you regarding WOL:
    My server broadcasts it's IP across the network to be discoverable as a uPNP-server. I'm guessing that functionality will be lost if it is turned off, so I should configure all my uPNP-clients to send a magical packet whenever I decide to use them (which would be nearly impossible: I don't see this possibility for a PS3...)
    I am not an expert in uPNP, but I am afraid that there is not a lot of solutions to your problem. If your server is powered off, then something has to wake him up. You can probably do that from your laptop/desktop or your router directly but I do not think a PS3 can do it. And having to send the magic packet manually each time you want to use a uPNP device kind of defeat the convenience of the uPNP.

  • Some init scripts disappeared?

    Hi
    I upgraded using pacman -Syu yesterday, then I found some init scripts(/etc/rc.d/nginx  /etc/rc.d/postgresql) disappeared.
    I searched about it but found nothing.

    peonone wrote:I searched about it but found nothing.
    Really?
    Read the front page news:
    https://www.archlinux.org/news/end-of-i … s-support/
    https://www.archlinux.org/news/final-sy … n-warning/

  • Arch32 init script in wiki incorrect ?

    Hi all,
    after the death of my 500GB SATA drive I had to (re)install arch64 on my box. For setting up the arch32 chroot I followed the guide as found in the wiki here:
    http://wiki.archlinux.org/index.php/Ins … _in_Arch64
    Unfortunately this new arch32 init script...
    #!/bin/bash
    . /etc/rc.conf
    . /etc/rc.d/functions
    dirs=(/proc /proc/bus/usb /dev /dev/pts /dev/shm /sys /tmp /home)
    case $1 in
    start)
    stat_busy "Starting Arch32 chroot"
    for d in "${dirs[@]}"; do
    mount --bind $d /opt/arch32/$d
    done
    add_daemon arch32
    stat_done
    stop)
    stat_busy "Stopping Arch32 chroot"
    for d in "${dirs[@]}"; do
    umount -l /opt/arch32/$d
    done
    rm_daemon arch32
    stat_done
    restart)
    $0 stop
    sleep 1
    $0 start
    echo "usage: $0 {start|stop|restart}"
    esac
    exit 0
    ...gives me the following error when I try to start the 32 bit chroot:
    :: Starting Arch32 chroot                                                [DONE]
    ./arch32_new: Zeile 16:  : Kommando nicht gefunden. <- this means command not found.
    Fortunately I had archived several pages from the wiki as pdf when I set back my first arch64 system. The old arch32 init script looks like this:
    #!/bin/bash
    . /etc/rc.conf
    . /etc/rc.d/functions
    case $1 in
    start)
    stat_busy "Starting Arch32 chroot"
    mount --bind /proc /opt/arch32/proc
    mount --bind /proc/bus/usb /opt/arch32/proc/bus/usb
    mount --bind /dev /opt/arch32/dev
    mount --bind /dev/pts /opt/arch32/dev/pts
    mount --bind /dev/shm /opt/arch32/dev/shm
    mount --bind /sys /opt/arch32/sys
    mount --bind /tmp /opt/arch32/tmp
    mount --bind /home /opt/arch32/home
    add_daemon arch32
    stat_done
    stop)
    stat_busy "Stopping Arch32 chroot"
    umount /opt/arch32/proc/bus/usb
    umount /opt/arch32/proc
    umount /opt/arch32/dev/pts
    umount /opt/arch32/dev/shm
    umount /opt/arch32/dev
    umount /opt/arch32/sys
    umount /opt/arch32/tmp
    umount /opt/arch32/home
    rm_daemon arch32
    stat_done
    restart)
    $0 stop
    sleep 1
    $0 start
    echo "usage: $0 {start|stop|restart}"
    esac
    exit 0
    This one works perfectly for me.
    Questions:
    - Has anyone of you used the new script without error message ?
    - What could cause the "command missing" error message ?
    I can post the old script in the wiki if the new one has errors.
    Regards,
    D$

    The script does seem to be a little broken alright, try with this one (untested)
    #!/bin/bash
    . /etc/rc.conf
    . /etc/rc.d/functions
    dirs=(proc proc/bus/usb dev dev/pts dev/shm sys tmp home)
    case $1 in
    start)
    stat_busy "Starting Arch32 chroot"
    for d in "${dirs[@]}"; do
    mount --bind /$d /opt/arch32/$d
    done
    add_daemon arch32
    stat_done
    stop)
    stat_busy "Stopping Arch32 chroot"
    for d in "${dirs[@]}"; do
    umount -l /opt/arch32/$d
    done
    rm_daemon arch32
    stat_done
    restart)
    $0 stop
    sleep 1
    $0 start
    echo "usage: $0 {start|stop|restart}"
    esac
    exit 0

  • Init script startup

    How does the init script system on Arch work? Coming from Ubuntu, if I wanted to add a startup script I just added it to /etc/init.d and ran update-init.d to create the necessary symlinks.
    I've looked on the wiki and searched the forum, but not found much on it. If I wanted to add a startup script, what's the best approach? It seems like the recommended way is to add the script to rc.d and to add a line to execute it in rc.local.

    It doesn't matter if it's a daemon or not, look for example at the /etc/rc.d/alsa script. It sure isn't a daemon but it's still in /etc/rc.d/ and it's still called from the daemons array in rc.conf . No, there are no symlinks, which simply means there isn't a program neither.

  • Geany Trouble: Compiling Perl Scripts (and general Perl questions)

    I'm brand new to Perl because I hear it's one of the best and so far I've found that it is.  I used to program a little C++ here and there and a while ago taught myself python but I'd have to say Perl is better than both of them.  At any rate, that's neither here nor there.  I use Geany and love it, so I didn't see a reason to switch to something new for Perl.  Unfortunately I'm having some trouble with compiling.  Geany flat out refuses to.  I looked around and didn't find anything on here or in the wiki or on the Ubuntu forums other than one person who said to replace the compile command with the execute command. 
    So, do I even need to compile my Perl scripts or is there something else I'm missing?
    On a somewhat related note, the same user on the Ubuntu forums said that at the top of the code there should be:
    #!/usr/bin/perl -w
    I'm curious if I need the "-w" or what it even does since as of right now I have
    #!/usr/bin/perl
    and executing the program poses no problems.
    Any help is greatly appreciated,
    --Wes

    Well, for one, perl is not a compiled language. You can if you want to, but it gains you few benefits. Google for "perl compiler" if you really must.
    As for the second, do you know how the shebang line works in unix, and do you know what the -w option does for perl? The answer should reveal itself to you.
    Make sure you "use strict;", it will catch many errors.

  • My compile shell script can't work when using flex4 sdk beta2

    I worked with flex4 sdk beta 1, and the compile script worked well. for example:
    mxmlc -debug=true -output=../main.swf -source-path ./src /usr/local/software/flash/open_source -- ./src/main.as
    But, when i chang into beta2, it shows some errors which are about  RSL things as the follows:
    D:\setup_bak\flashbuilder4beta2\testFlex4.as: 警告: 此编译单元不包含在 Frame 元
    数据中指定的 factoryClass,无法加载配置的运行时共享库。要在没有运行时共享库的情
    况下进行编译,请将 -static-link-runtime-shared-libraries 选项设置为 true,或删除
    -runtime-shared-libraries 选项。
    So I use -dump-config option to generate a config xml, when i using the config xml, i got an error as the follows:
    错误: 必须指定目标文件
    使用“mxmlc -help”可获得有关如何使用命令行的信息。
    Any one can tell me why?
    sorry for my english, i don't known whether i describe my problem clearly. Thank for reading this thread.

    Compile success when i set -static-link-runtime-shared-libraries=true.
    I thought that the size of swf would increase a lot because of a static link, but the size is 727 byte..
    yes, it is a pure AS app extends Sprite. The code is so simple:
    package
         import flash.display.Sprite;
         public class testFlex4 extends Sprite
             public function testFlex4()
    the compile cmd which got an error is simple too:
    mxmlc -debug=true -output=testFlex4.swf -source-path ./ -- testFlex4.as
    the compile cmd which works find is:
    mxmlc -debug=true -static-link-runtime-shared-libraries=true -output=testFlex4.swf -source-path ./ -- testFlex4.as
    When you said "file a bug", you meant "adobe bug system" at "http://bugs.adobe.com/jira/secure/Dashboard.jspa"??
    I signup an account half an hour ago, but i cant login with it...and i can't get an "forget password" email..it seems that i blew it..i am so sorry for this..

  • Openrc init scripts source?

    I have been using openrc as my init system, with apg's method. I have had no issues, however, I would like to know if there is some kind of repo for openrc scripts, as till now, I have been writing many initscripts in my own.
    EDIT: I have also been extracting artoo's packages and using those initscripts, but it is a very few scripts.
    Last edited by aditya3098 (2014-10-29 15:21:23)

    To my knowlage there is no such a repo/site. Our openrc implementation is unofficial and community driven which means it gets less support, plus we have two incompatible implementations. One of us could start a github (or something like that) repo and keep all our home made scripts/rules etc. Would like to see that happen, and soon I may have something to contribute with.

Maybe you are looking for

  • Not able to find values in LOV of field "Help Desk" of Global contract

    Not able to find values in LOV of field "Help Desk" of Global contract defaults. This value should be coming from resource setup. Resource is already created.

  • Problem with installing adobe illustrator cs6?

    I am having trouble installing adobe illustrator cs6.When it gets to 2% it says "the setup encountered an error (37) during install. Please restart the machine and try again." I tried restarting my computer but it still shows that message. Also at th

  • Referencing field in a query struct

    About 5% of the time I get an error 'Element COMPANYSTATUS is undefined in Q.' from the code in SNIPPET 1. Can anyone tell me why I would ever get this error? If the query returns 0 results (which it may if the user is not logged in and SESSION.User.

  • How to Migrate BSP applications into WDA

    Hi,   We have some BSP application,is it possible to migrate BSP application into WDA or we need to

  • We need an "Undo Autocorrect" button/method

    It would be great to have a button/button combo that would undo the last autocorrection made and revert to the intended spelling. Autocorrect as a whole is an excellent feature. What would make it even better is the option to undo the last autocorrec