Refactor little progname() for all applictions

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2016-11-27 17:38:01 +01:00
parent 829ff0b9f7
commit f24a03a32c
7 changed files with 94 additions and 22 deletions
+3 -2
View File
@@ -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
+4 -2
View File
@@ -30,6 +30,7 @@
#include <lite/lite.h>
#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':
-2
View File
@@ -95,8 +95,6 @@ extern char *runparts;
extern char *console;
extern uev_ctx_t *ctx;
extern char *__progname;
#endif /* FINIT_H_ */
/**
+3 -1
View File
@@ -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':
+2 -15
View File
@@ -28,6 +28,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/reboot.h>
#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) {
+44
View File
@@ -0,0 +1,44 @@
/* Misc. shared utility functions for initctl, reboot and finit
*
* Copyright (c) 2016 Joachim Nilsson <troglobit@gmail.com>
*
* 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 <string.h>
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:
*/
+38
View File
@@ -0,0 +1,38 @@
/* Misc. shared utility functions for initctl, reboot and finit
*
* Copyright (c) 2016 Joachim Nilsson <troglobit@gmail.com>
*
* 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:
*/