mirror of
https://github.com/troglobit/finit.git
synced 2026-11-07 16:01:08 +00:00
Refactor little progname() for all applictions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
829ff0b9f7
commit
f24a03a32c
7 files changed
+94
-22
No files matched your search
+3
-2
@@ -14,6 +14,7 @@ finit_SOURCES = api.c \
|
|||||||
sm.c sm.h \
|
sm.c sm.h \
|
||||||
svc.c svc.h \
|
svc.c svc.h \
|
||||||
tty.c tty.h \
|
tty.c tty.h \
|
||||||
|
util.c util.h \
|
||||||
utmp-api.c utmp-api.h
|
utmp-api.c utmp-api.h
|
||||||
pkginclude_HEADERS = cond.h finit.h helpers.h inetd.h plugin.h svc.h
|
pkginclude_HEADERS = cond.h finit.h helpers.h inetd.h plugin.h svc.h
|
||||||
if INETD
|
if INETD
|
||||||
@@ -32,11 +33,11 @@ finit_LDADD += -ldl
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
initctl_SOURCES = initctl.c svc.c svc.h helpers.c helpers.h cond.c cond.h \
|
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_CFLAGS = $(lite_CFLAGS)
|
||||||
initctl_LDADD = $(lite_LIBS)
|
initctl_LDADD = $(lite_LIBS)
|
||||||
|
|
||||||
reboot_SOURCES = reboot.c
|
reboot_SOURCES = reboot.c util.c util.h
|
||||||
|
|
||||||
INIT_LNKS = telinit init
|
INIT_LNKS = telinit init
|
||||||
REBOOT_LNKS = shutdown halt poweroff suspend
|
REBOOT_LNKS = shutdown halt poweroff suspend
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <lite/lite.h>
|
#include <lite/lite.h>
|
||||||
|
|
||||||
#include "finit.h"
|
#include "finit.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static int do_send(struct init_request *rq)
|
static int do_send(struct init_request *rq)
|
||||||
{
|
{
|
||||||
@@ -39,7 +40,7 @@ static int do_send(struct init_request *rq)
|
|||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
if (!fexist(FINIT_FIFO)) {
|
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;
|
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"
|
" q, Q Reload *.conf in /etc/finit.d/, same as initctl reload or\n"
|
||||||
" sending SIGHUP to PID 1\n"
|
" sending SIGHUP to PID 1\n"
|
||||||
" 1, s, S Enter system rescue mode, runlevel 1\n"
|
" 1, s, S Enter system rescue mode, runlevel 1\n"
|
||||||
"\n", __progname);
|
"\n", prognm);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -123,6 +124,7 @@ int client(int argc, char *argv[])
|
|||||||
};
|
};
|
||||||
|
|
||||||
silent = 1;
|
silent = 1;
|
||||||
|
progname(argv[0]);
|
||||||
while ((c = getopt_long(argc, argv, "h?v", long_options, NULL)) != EOF) {
|
while ((c = getopt_long(argc, argv, "h?v", long_options, NULL)) != EOF) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'v':
|
case 'v':
|
||||||
|
|||||||
@@ -95,8 +95,6 @@ extern char *runparts;
|
|||||||
extern char *console;
|
extern char *console;
|
||||||
extern uev_ctx_t *ctx;
|
extern uev_ctx_t *ctx;
|
||||||
|
|
||||||
extern char *__progname;
|
|
||||||
|
|
||||||
#endif /* FINIT_H_ */
|
#endif /* FINIT_H_ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include "cond.h"
|
#include "cond.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
|
#include "util.h"
|
||||||
#include "utmp-api.h"
|
#include "utmp-api.h"
|
||||||
|
|
||||||
#define _PATH_COND _PATH_VARRUN "finit/cond/"
|
#define _PATH_COND _PATH_VARRUN "finit/cond/"
|
||||||
@@ -439,7 +440,7 @@ static int usage(int rc)
|
|||||||
" halt Halt system\n"
|
" halt Halt system\n"
|
||||||
" poweroff Halt and power off system\n"
|
" poweroff Halt and power off system\n"
|
||||||
" utmp show Raw dump of UTMP/WTMP db\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;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -471,6 +472,7 @@ int main(int argc, char *argv[])
|
|||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
progname(argv[0]);
|
||||||
while ((c = getopt_long(argc, argv, "dh?v", long_options, NULL)) != EOF) {
|
while ((c = getopt_long(argc, argv, "dh?v", long_options, NULL)) != EOF) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/reboot.h>
|
#include <sys/reboot.h>
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#ifndef RB_SW_SUSPEND /* Since Linux 2.5.18, but not in GLIBC until 2.19 */
|
#ifndef RB_SW_SUSPEND /* Since Linux 2.5.18, but not in GLIBC until 2.19 */
|
||||||
#define RB_SW_SUSPEND 0xd000fce2
|
#define RB_SW_SUSPEND 0xd000fce2
|
||||||
@@ -43,7 +44,6 @@ typedef enum {
|
|||||||
|
|
||||||
static cmd_t cmd = CMD_UNKNOWN;
|
static cmd_t cmd = CMD_UNKNOWN;
|
||||||
static char *msg = NULL;
|
static char *msg = NULL;
|
||||||
static char *prognm;
|
|
||||||
|
|
||||||
static void translate(void)
|
static void translate(void)
|
||||||
{
|
{
|
||||||
@@ -96,19 +96,6 @@ static int usage(int rc)
|
|||||||
return 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 main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int c, force = 0;
|
int c, force = 0;
|
||||||
@@ -122,7 +109,7 @@ int main(int argc, char *argv[])
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Initial command taken from program name */
|
/* Initial command taken from program name */
|
||||||
prognm = progname(argv[0]);
|
progname(argv[0]);
|
||||||
translate();
|
translate();
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "h?fHpr", long_options, NULL)) != EOF) {
|
while ((c = getopt_long(argc, argv, "h?fHpr", long_options, NULL)) != EOF) {
|
||||||
|
|||||||
@@ -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:
|
||||||
|
*/
|
||||||
@@ -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:
|
||||||
|
*/
|
||||||
Reference in new issue
Block a user