diff --git a/Makefile.am b/Makefile.am index 1ac14fdb..e3124c9b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,6 +14,7 @@ finit_SOURCES = api.c \ sm.c sm.h \ svc.c svc.h \ tty.c tty.h \ + util.c util.h \ utmp-api.c utmp-api.h pkginclude_HEADERS = cond.h finit.h helpers.h inetd.h plugin.h svc.h if INETD @@ -32,11 +33,11 @@ finit_LDADD += -ldl endif initctl_SOURCES = initctl.c svc.c svc.h helpers.c helpers.h cond.c cond.h \ - utmp-api.c utmp-api.h + util.c util.h utmp-api.c utmp-api.h initctl_CFLAGS = $(lite_CFLAGS) initctl_LDADD = $(lite_LIBS) -reboot_SOURCES = reboot.c +reboot_SOURCES = reboot.c util.c util.h INIT_LNKS = telinit init REBOOT_LNKS = shutdown halt poweroff suspend diff --git a/client.c b/client.c index fa2edfc4..231895fc 100644 --- a/client.c +++ b/client.c @@ -30,6 +30,7 @@ #include #include "finit.h" +#include "util.h" static int do_send(struct init_request *rq) { @@ -39,7 +40,7 @@ static int do_send(struct init_request *rq) if (fd == -1) { if (!fexist(FINIT_FIFO)) { - fprintf(stderr, "%s does not support %s!\n", __progname, FINIT_FIFO); + fprintf(stderr, "%s does not support %s!\n", prognm, FINIT_FIFO); return 1; } @@ -108,7 +109,7 @@ static int usage(int rc) " q, Q Reload *.conf in /etc/finit.d/, same as initctl reload or\n" " sending SIGHUP to PID 1\n" " 1, s, S Enter system rescue mode, runlevel 1\n" - "\n", __progname); + "\n", prognm); return rc; } @@ -123,6 +124,7 @@ int client(int argc, char *argv[]) }; silent = 1; + progname(argv[0]); while ((c = getopt_long(argc, argv, "h?v", long_options, NULL)) != EOF) { switch(c) { case 'v': diff --git a/finit.h b/finit.h index 285da21c..4e01c21d 100644 --- a/finit.h +++ b/finit.h @@ -95,8 +95,6 @@ extern char *runparts; extern char *console; extern uev_ctx_t *ctx; -extern char *__progname; - #endif /* FINIT_H_ */ /** diff --git a/initctl.c b/initctl.c index 39c00c04..6e2ab2c7 100644 --- a/initctl.c +++ b/initctl.c @@ -38,6 +38,7 @@ #include "cond.h" #include "helpers.h" #include "service.h" +#include "util.h" #include "utmp-api.h" #define _PATH_COND _PATH_VARRUN "finit/cond/" @@ -439,7 +440,7 @@ static int usage(int rc) " halt Halt system\n" " poweroff Halt and power off system\n" " utmp show Raw dump of UTMP/WTMP db\n" - " version Show Finit version\n\n", __progname); + " version Show Finit version\n\n", prognm); return rc; } @@ -471,6 +472,7 @@ int main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; + progname(argv[0]); while ((c = getopt_long(argc, argv, "dh?v", long_options, NULL)) != EOF) { switch(c) { case 'h': diff --git a/reboot.c b/reboot.c index 2b47b70a..29e7bf0c 100644 --- a/reboot.c +++ b/reboot.c @@ -28,6 +28,7 @@ #include #include #include +#include "util.h" #ifndef RB_SW_SUSPEND /* Since Linux 2.5.18, but not in GLIBC until 2.19 */ #define RB_SW_SUSPEND 0xd000fce2 @@ -43,7 +44,6 @@ typedef enum { static cmd_t cmd = CMD_UNKNOWN; static char *msg = NULL; -static char *prognm; static void translate(void) { @@ -96,19 +96,6 @@ static int usage(int rc) return rc; } -static char *progname(char *arg0) -{ - char *nm; - - nm = strrchr(arg0, '/'); - if (nm) - nm++; - else - nm = arg0; - - return nm; -} - int main(int argc, char *argv[]) { int c, force = 0; @@ -122,7 +109,7 @@ int main(int argc, char *argv[]) }; /* Initial command taken from program name */ - prognm = progname(argv[0]); + progname(argv[0]); translate(); while ((c = getopt_long(argc, argv, "h?fHpr", long_options, NULL)) != EOF) { diff --git a/util.c b/util.c new file mode 100644 index 00000000..9ed4efba --- /dev/null +++ b/util.c @@ -0,0 +1,44 @@ +/* Misc. shared utility functions for initctl, reboot and finit + * + * Copyright (c) 2016 Joachim Nilsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +char *prognm = NULL; + +char *progname(char *arg0) +{ + prognm = strrchr(arg0, '/'); + if (prognm) + prognm++; + else + prognm = arg0; + + return prognm; +} + +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */ diff --git a/util.h b/util.h new file mode 100644 index 00000000..8305eb2d --- /dev/null +++ b/util.h @@ -0,0 +1,38 @@ +/* Misc. shared utility functions for initctl, reboot and finit + * + * Copyright (c) 2016 Joachim Nilsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef FINIT_UTIL_H_ +#define FINIT_UTIL_H_ + +extern char *prognm; + +char *progname(char *arg0); + +#endif /* FINIT_UTIL_H_ */ + +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */