[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Root checked moved after parsing the command line.
From: |
Alfred M. Szmidt |
Subject: |
Root checked moved after parsing the command line. |
Date: |
24 Jun 2002 03:20:42 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
Hi,
This moves the checking of root in ping to a later stage, i.e. after
parsing the command line. This is so that --help can be a bit of use
for users instead of spitting out an "must run as root" message. Oh,
it also moves the variable is_root into main().
OK to commit?
ping/ChangeLog
2002-06-24 Alfred M. Szmidt <address@hidden>
* ping.c (main): Moved ping startup code to after the parsing
of the command line.
(is_root): Variable moved into main().
--- ping.c.~1.9.~ Mon Jun 24 02:40:20 2002
+++ ping.c Mon Jun 24 03:06:29 2002
@@ -86,7 +86,6 @@ extern int ping_address __P ((int argc,
extern int ping_router __P ((int argc, char **argv));
PING *ping;
-int is_root; /* were we started with root privileges */
u_char *data_buffer;
size_t data_length = PING_DATALEN;
unsigned options;
@@ -111,18 +110,7 @@ main (int argc, char **argv)
u_char pattern[16];
int pattern_len = 16;
u_char *patptr = NULL;
-
- is_root = getuid () == 0;
-
- if ((ping = ping_init (ICMP_ECHO, getpid ())) == NULL)
- {
- fprintf (stderr, "can't init ping: %s\n", strerror (errno));
- exit (1);
- }
- ping_set_sockopt (ping, SO_BROADCAST, (char *)&one, sizeof (one));
-
- /* Reset root privileges */
- setuid (getuid ());
+ int is_root = getuid () == 0;
/* Parse command line */
while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
@@ -235,6 +223,17 @@ main (int argc, char **argv)
}
init_data_buffer (patptr, pattern_len);
+
+ ping = ping_init (ICMP_ECHO, getpid ());
+ if (ping == NULL)
+ {
+ fprintf (stderr, "can't init ping: %s\n", strerror (errno));
+ exit (1);
+ }
+ ping_set_sockopt (ping, SO_BROADCAST, (char *)&one, sizeof (one));
+
+ /* Reset root privileges */
+ setuid (getuid ());
return (*ping_type)(argc, argv);
}
--
Alfred M. Szmidt
- Root checked moved after parsing the command line.,
Alfred M. Szmidt <=