skill: clean up which functionality is being called

The skill.c is three different commands depending on how the
executable is named. This patch makes evaluation of the command name
cleaner.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-10-16 15:13:22 +02:00
parent 57f290dcb4
commit 4c8446dc55

39
skill.c
View File

@ -49,11 +49,13 @@ static int saved_argc;
static int sig_or_pri; static int sig_or_pri;
static int program = -1; enum {
#define PROG_KILL 1 PROG_UNKNOWN,
#define PROG_SKILL 2 PROG_KILL,
/*#define PROG_NICE 3*/ /* easy, but the old one isn't broken */ PROG_SKILL,
#define PROG_SNICE 4 PROG_SNICE
};
static int program = PROG_UNKNOWN;
static void display_kill_version(void) static void display_kill_version(void)
{ {
@ -651,24 +653,18 @@ static void skillsnice_parse(int argc,
/* main body */ /* main body */
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
const char *tmpstr;
my_pid = getpid(); my_pid = getpid();
saved_argc = argc;
if (!argc) { if (strcmp(program_invocation_short_name, "kill") == 0 ||
fprintf(stderr, _("ERROR: could not determine own name.\n")); strcmp(program_invocation_short_name, "lt-kill") == 0)
exit(1);
}
tmpstr = strrchr(*argv, '/');
if (tmpstr)
tmpstr++;
if (!tmpstr)
tmpstr = *argv;
if (strstr(tmpstr, "kill"))
program = PROG_KILL; program = PROG_KILL;
if (strstr(tmpstr, "skill")) else if (strcmp(program_invocation_short_name, "skill") == 0 ||
strcmp(program_invocation_short_name, "lt-skill") == 0)
program = PROG_SKILL; program = PROG_SKILL;
if (strstr(tmpstr, "snice")) else if (strcmp(program_invocation_short_name, "snice") == 0 ||
strcmp(program_invocation_short_name, "lt-snice") == 0)
program = PROG_SNICE; program = PROG_SNICE;
switch (program) { switch (program) {
case PROG_SNICE: case PROG_SNICE:
case PROG_SKILL: case PROG_SKILL:
@ -682,7 +678,10 @@ int main(int argc, const char *argv[])
kill_main(argc, argv); kill_main(argc, argv);
break; break;
default: default:
fprintf(stderr, _("ERROR: no \"%s\" support.\n"), tmpstr); fprintf(stderr, _("skill: \"%s\" is not support\n"),
program_invocation_short_name);
fprintf(stderr, USAGE_MAN_TAIL("skill(1)"));
return 1;
} }
return 0; return 0;
} }