skill: fix compiler warnings

Pretty much all of the warnings where caused by some of the previous
patches, and they became visible with gcc when compiling with;

CFLAGS="-O -g -ggdb -Wall -Wextra -pedantic -Wstrict-overflow
	-Wformat -Wswitch-default -Wswitch-enum -Wsync-nand
	-Wredundant-decls -Wuninitialized"

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-10-22 20:32:29 +02:00
parent d8d94a87ef
commit 1ac2921f6f

62
skill.c
View File

@ -8,10 +8,11 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details. * GNU Library General Public License for more details.
*/ */
#include <ctype.h>
#include <dirent.h> #include <dirent.h>
#include <getopt.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <getopt.h>
#include <limits.h> #include <limits.h>
#include <pwd.h> #include <pwd.h>
#include <signal.h> #include <signal.h>
@ -78,7 +79,6 @@ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd,
struct run_time_conf_t *run_time) struct run_time_conf_t *run_time)
{ {
int failed; int failed;
int saved_errno;
char dn_buf[1000]; char dn_buf[1000];
dev_to_tty(dn_buf, 999, tty, pid, ABBREV_DEV); dev_to_tty(dn_buf, 999, tty, pid, ABBREV_DEV);
if (run_time->interactive) { if (run_time->interactive) {
@ -93,25 +93,19 @@ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd,
return; return;
} }
/* do the actual work */ /* do the actual work */
errno = 0;
if (program == PROG_SKILL) if (program == PROG_SKILL)
failed = kill(pid, sig_or_pri); failed = kill(pid, sig_or_pri);
else else
failed = setpriority(PRIO_PROCESS, pid, sig_or_pri); failed = setpriority(PRIO_PROCESS, pid, sig_or_pri);
saved_errno = errno; if ((run_time->warnings && failed) || run_time->debugging || run_time->verbose) {
if ((run_time->warnings && failed) || run_time->debugging) {
fprintf(stderr, "%-8s %-8s %5d %-16.16s ", fprintf(stderr, "%-8s %-8s %5d %-16.16s ",
(char *)dn_buf, user_from_uid(uid), pid, cmd); (char *)dn_buf, user_from_uid(uid), pid, cmd);
errno = saved_errno;
perror(""); perror("");
return; return;
} }
if (run_time->interactive) if (run_time->interactive)
return; return;
if (run_time->verbose) {
printf("%-8s %-8s %5d %-16.16s\n",
(char *)dn_buf, user_from_uid(uid), pid, cmd);
return;
}
if (run_time->noaction) { if (run_time->noaction) {
printf("%d\n", pid); printf("%d\n", pid);
return; return;
@ -329,11 +323,30 @@ static void __attribute__ ((__noreturn__)) skillsnice_usage(FILE * out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
} }
int skill_sig_option(int *argc, char **argv)
{
int i, nargs = *argc;
int signo = -1;
for (i = 1; i < nargs; i++) {
if (argv[i][0] == '-') {
signo = signal_name_to_number(argv[i] + 1);
if (-1 < signo) {
if (nargs - i) {
nargs--;
memmove(argv + i, argv + i + 1,
sizeof(char *) * (nargs - i));
}
return signo;
}
}
}
return signo;
}
/* kill */ /* kill */
static void __attribute__ ((__noreturn__)) static void __attribute__ ((__noreturn__))
kill_main(int argc, char **argv, struct run_time_conf_t *run_time) kill_main(int argc, char **argv)
{ {
const char *sigptr;
int signo, i; int signo, i;
int sigopt = 0; int sigopt = 0;
long pid; long pid;
@ -440,32 +453,11 @@ int snice_prio_option(int *argc, char **argv)
return (int)prio; return (int)prio;
} }
int skill_sig_option(int *argc, char **argv)
{
int i, nargs = *argc;
int signo = -1;
for (i = 1; i < nargs; i++) {
if (argv[i][0] == '-') {
signo = signal_name_to_number(argv[i] + 1);
if (-1 < signo) {
if (nargs - i) {
nargs--;
memmove(argv + i, argv + i + 1,
sizeof(char *) * (nargs - i));
}
return signo;
}
}
}
return signo;
}
static void skillsnice_parse(int argc, static void skillsnice_parse(int argc,
char **argv, struct run_time_conf_t *run_time) char **argv, struct run_time_conf_t *run_time)
{ {
int signo = -1; int signo = -1;
int prino = DEFAULT_NICE; int prino = DEFAULT_NICE;
int force = 0;
int num_found = 0; int num_found = 0;
int ch, i; int ch, i;
const char *restrict argptr; const char *restrict argptr;
@ -568,7 +560,7 @@ static void skillsnice_parse(int argc,
case 'u': case 'u':
{ {
struct passwd *passwd_data; struct passwd *passwd_data;
passwd_data = getpwnam(argptr); passwd_data = getpwnam(optarg);
if (passwd_data) { if (passwd_data) {
num_found++; num_found++;
ENLIST(uid, passwd_data->pw_uid); ENLIST(uid, passwd_data->pw_uid);
@ -651,7 +643,7 @@ int main(int argc, char ** argv)
iterate(&run_time); iterate(&run_time);
break; break;
case PROG_KILL: case PROG_KILL:
kill_main(argc, argv, &run_time); kill_main(argc, argv);
break; break;
default: default:
fprintf(stderr, _("skill: \"%s\" is not support\n"), fprintf(stderr, _("skill: \"%s\" is not support\n"),