mirror of
https://github.com/troglobit/finit.git
synced 2026-10-23 11:44:37 +00:00
reboot: Replace __progname with a small function
This patch removes the use of non-standard __progname and replaces it with a small function. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
5a1b13ff41
commit
a96b74ea5e
1 file changed
+19
-5
@@ -43,16 +43,16 @@ typedef enum {
|
|||||||
|
|
||||||
static cmd_t cmd = CMD_UNKNOWN;
|
static cmd_t cmd = CMD_UNKNOWN;
|
||||||
static char *msg = NULL;
|
static char *msg = NULL;
|
||||||
extern char *__progname;
|
extern char *prognm;
|
||||||
|
|
||||||
static void translate(void)
|
static void translate(void)
|
||||||
{
|
{
|
||||||
if (cmd == CMD_UNKNOWN) {
|
if (cmd == CMD_UNKNOWN) {
|
||||||
if (!strcmp(__progname, "halt") || !strcmp(__progname, "shutdown"))
|
if (!strcmp(prognm, "halt") || !strcmp(prognm, "shutdown"))
|
||||||
cmd = CMD_HALT;
|
cmd = CMD_HALT;
|
||||||
else if (!strcmp(__progname, "poweroff"))
|
else if (!strcmp(prognm, "poweroff"))
|
||||||
cmd = CMD_POWEROFF;
|
cmd = CMD_POWEROFF;
|
||||||
else if (!strcmp(__progname, "suspend"))
|
else if (!strcmp(prognm, "suspend"))
|
||||||
cmd = CMD_SUSPEND;
|
cmd = CMD_SUSPEND;
|
||||||
else
|
else
|
||||||
cmd = CMD_REBOOT;
|
cmd = CMD_REBOOT;
|
||||||
@@ -91,11 +91,24 @@ static int usage(int rc)
|
|||||||
" --halt Halt system, regardless of how the command is called.\n"
|
" --halt Halt system, regardless of how the command is called.\n"
|
||||||
" -p, --poweroff Power-off system, regardless of how the command is called.\n"
|
" -p, --poweroff Power-off system, regardless of how the command is called.\n"
|
||||||
" --reboot Reboot system, regardless of how the command is called.\n"
|
" --reboot Reboot system, regardless of how the command is called.\n"
|
||||||
"\n", __progname, msg);
|
"\n", prognm, msg);
|
||||||
|
|
||||||
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;
|
||||||
@@ -111,6 +124,7 @@ int main(int argc, char *argv[])
|
|||||||
/* Initial command taken from program name */
|
/* Initial command taken from program name */
|
||||||
translate();
|
translate();
|
||||||
|
|
||||||
|
prognm = progname(argv[0]);
|
||||||
while ((c = getopt_long(argc, argv, "h?fHpr", long_options, NULL)) != EOF) {
|
while ((c = getopt_long(argc, argv, "h?fHpr", long_options, NULL)) != EOF) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
|
|||||||
Reference in new issue
Block a user