Rob Sullivan sent in some cleanups, which I beat on slightly.
This commit is contained in:
parent
0f34a821ab
commit
1b751c894b
@ -4,7 +4,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <getopt.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -76,40 +75,20 @@ int makedevs_main(int argc, char **argv)
|
|||||||
|
|
||||||
#elif defined CONFIG_FEATURE_MAKEDEVS_TABLE
|
#elif defined CONFIG_FEATURE_MAKEDEVS_TABLE
|
||||||
|
|
||||||
/*
|
/* Licensed under the GPL v2 or later, see the file LICENSE in this tarball. */
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern int makedevs_main(int argc, char **argv)
|
extern int makedevs_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int opt;
|
|
||||||
FILE *table = stdin;
|
FILE *table = stdin;
|
||||||
char *rootdir = NULL;
|
char *rootdir = NULL;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
int linenum = 0;
|
int linenum = 0;
|
||||||
int ret = EXIT_SUCCESS;
|
int ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "d:")) != -1) {
|
unsigned long flags;
|
||||||
switch(opt) {
|
flags = bb_getopt_ulflags(argc, argv, "d:", &line);
|
||||||
case 'd':
|
if (line)
|
||||||
table = bb_xfopen((line=optarg), "r");
|
table = bb_xfopen(line, "r");
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind >= argc || (rootdir=argv[optind])==NULL) {
|
if (optind >= argc || (rootdir=argv[optind])==NULL) {
|
||||||
bb_error_msg_and_die("root directory not specified");
|
bb_error_msg_and_die("root directory not specified");
|
||||||
@ -159,16 +138,9 @@ extern int makedevs_main(int argc, char **argv)
|
|||||||
if (name[0] == '#') {
|
if (name[0] == '#') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (group) {
|
|
||||||
gid = get_ug_id(group, bb_xgetgrnam);
|
gid = group ? get_ug_id(group, bb_xgetgrnam) : getgid();
|
||||||
} else {
|
uid = user ? get_ug_id(user, bb_xgetpwnam) : getuid();
|
||||||
gid = getgid();
|
|
||||||
}
|
|
||||||
if (user) {
|
|
||||||
uid = get_ug_id(user, bb_xgetpwnam);
|
|
||||||
} else {
|
|
||||||
uid = getuid();
|
|
||||||
}
|
|
||||||
full_name = concat_path_file(rootdir, name);
|
full_name = concat_path_file(rootdir, name);
|
||||||
|
|
||||||
if (type == 'd') {
|
if (type == 'd') {
|
||||||
|
@ -4,20 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org>
|
* Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -40,19 +27,14 @@ static void watchdog_shutdown(int unused)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int watchdog_main(int argc, char **argv)
|
int watchdog_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int opt;
|
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "t:")) > 0) {
|
char *t_arg;
|
||||||
switch (opt) {
|
unsigned long flags;
|
||||||
case 't':
|
flags = bb_getopt_ulflags(argc, argv, "t:", &t_arg);
|
||||||
timer_duration = bb_xgetlarg(optarg, 10, 0, INT_MAX);
|
if (flags & 1)
|
||||||
break;
|
timer_duration = bb_xgetlarg(t_arg, 10, 0, INT_MAX);
|
||||||
default:
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We're only interested in the watchdog device .. */
|
/* We're only interested in the watchdog device .. */
|
||||||
if (optind < argc - 1 || argc == 1)
|
if (optind < argc - 1 || argc == 1)
|
||||||
|
@ -12,19 +12,7 @@
|
|||||||
* Lines in the interfaces file cannot wrap.
|
* Lines in the interfaces file cannot wrap.
|
||||||
* To adhere to the FHS, the default state file is /var/run/ifstate.
|
* To adhere to the FHS, the default state file is /var/run/ifstate.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* TODO: standardise execute() return codes to return 0 for success and 1 for failure */
|
/* TODO: standardise execute() return codes to return 0 for success and 1 for failure */
|
||||||
@ -819,7 +807,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add the interface to the list */
|
/* Add the interface to the list */
|
||||||
defn->autointerfaces = llist_add_to_end(defn->autointerfaces, strdup(firstword));
|
defn->autointerfaces = llist_add_to_end(defn->autointerfaces, bb_xstrdup(firstword));
|
||||||
debug_noise("\nauto %s\n", firstword);
|
debug_noise("\nauto %s\n", firstword);
|
||||||
}
|
}
|
||||||
currently_processing = NONE;
|
currently_processing = NONE;
|
||||||
@ -1254,7 +1242,7 @@ extern int ifupdown_main(int argc, char **argv)
|
|||||||
const llist_t *list = state_list;
|
const llist_t *list = state_list;
|
||||||
while (list) {
|
while (list) {
|
||||||
new_item = xmalloc(sizeof(llist_t));
|
new_item = xmalloc(sizeof(llist_t));
|
||||||
new_item->data = strdup(list->data);
|
new_item->data = bb_xstrdup(list->data);
|
||||||
new_item->link = NULL;
|
new_item->link = NULL;
|
||||||
list = target_list;
|
list = target_list;
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
@ -1273,7 +1261,7 @@ extern int ifupdown_main(int argc, char **argv)
|
|||||||
/* iface_down */
|
/* iface_down */
|
||||||
const llist_t *list = state_list;
|
const llist_t *list = state_list;
|
||||||
while (list) {
|
while (list) {
|
||||||
target_list = llist_add_to_end(target_list, strdup(list->data));
|
target_list = llist_add_to_end(target_list, bb_xstrdup(list->data));
|
||||||
list = list->link;
|
list = list->link;
|
||||||
}
|
}
|
||||||
target_list = defn->autointerfaces;
|
target_list = defn->autointerfaces;
|
||||||
@ -1294,15 +1282,15 @@ extern int ifupdown_main(int argc, char **argv)
|
|||||||
int okay = 0;
|
int okay = 0;
|
||||||
int cmds_ret;
|
int cmds_ret;
|
||||||
|
|
||||||
iface = strdup(target_list->data);
|
iface = bb_xstrdup(target_list->data);
|
||||||
target_list = target_list->link;
|
target_list = target_list->link;
|
||||||
|
|
||||||
pch = strchr(iface, '=');
|
pch = strchr(iface, '=');
|
||||||
if (pch) {
|
if (pch) {
|
||||||
*pch = '\0';
|
*pch = '\0';
|
||||||
liface = strdup(pch + 1);
|
liface = bb_xstrdup(pch + 1);
|
||||||
} else {
|
} else {
|
||||||
liface = strdup(iface);
|
liface = bb_xstrdup(iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!force) {
|
if (!force) {
|
||||||
|
@ -8,19 +8,7 @@
|
|||||||
* Created: Thu Apr 7 13:29:41 1994 too
|
* Created: Thu Apr 7 13:29:41 1994 too
|
||||||
* Last modified: Fri Jun 9 14:34:24 2000 too
|
* Last modified: Fri Jun 9 14:34:24 2000 too
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
*
|
||||||
* HISTORY
|
* HISTORY
|
||||||
* Revision 3.1 1994/04/17 11:31:54 too
|
* Revision 3.1 1994/04/17 11:31:54 too
|
||||||
@ -636,10 +624,6 @@ extern int telnet_main(int argc, char** argv)
|
|||||||
int maxfd;
|
int maxfd;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
|
|
||||||
int opt;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||||
get_terminal_width_height(0, &win_width, &win_height);
|
get_terminal_width_height(0, &win_width, &win_height);
|
||||||
#endif
|
#endif
|
||||||
@ -661,20 +645,10 @@ extern int telnet_main(int argc, char** argv)
|
|||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
|
#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
|
||||||
autologin = NULL;
|
unsigned long flags = bb_getopt_ulflags(argc, argv, "al:", &autologin);
|
||||||
while ((opt = getopt(argc, argv, "al:")) != EOF) {
|
if (flags & 1)
|
||||||
switch (opt) {
|
|
||||||
case 'l':
|
|
||||||
autologin = optarg;
|
|
||||||
break;
|
|
||||||
case 'a':
|
|
||||||
autologin = getenv("USER");
|
autologin = getenv("USER");
|
||||||
break;
|
|
||||||
case '?':
|
|
||||||
bb_show_usage();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
bb_lookup_host(&s_in, argv[optind++]);
|
bb_lookup_host(&s_in, argv[optind++]);
|
||||||
s_in.sin_port = bb_lookup_port((optind < argc) ? argv[optind++] :
|
s_in.sin_port = bb_lookup_port((optind < argc) ? argv[optind++] :
|
||||||
|
@ -5,20 +5,7 @@
|
|||||||
*
|
*
|
||||||
* by Sterling Huxley <sterling@europa.com>
|
* by Sterling Huxley <sterling@europa.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Licensed under GPL v2 or later, see file License for details.
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -27,7 +14,6 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <getopt.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -46,14 +32,14 @@ static void socket_timeout(int sig)
|
|||||||
|
|
||||||
static time_t askremotedate(const char *host)
|
static time_t askremotedate(const char *host)
|
||||||
{
|
{
|
||||||
unsigned long int nett, localt;
|
unsigned long nett;
|
||||||
struct sockaddr_in s_in;
|
struct sockaddr_in s_in;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
bb_lookup_host(&s_in, host);
|
bb_lookup_host(&s_in, host);
|
||||||
s_in.sin_port = bb_lookup_port("time", "tcp", 37);
|
s_in.sin_port = bb_lookup_port("time", "tcp", 37);
|
||||||
|
|
||||||
/* Add a timeout for dead or non accessable servers */
|
/* Add a timeout for dead or inaccessible servers */
|
||||||
alarm(10);
|
alarm(10);
|
||||||
signal(SIGALRM, socket_timeout);
|
signal(SIGALRM, socket_timeout);
|
||||||
|
|
||||||
@ -61,7 +47,6 @@ static time_t askremotedate(const char *host)
|
|||||||
|
|
||||||
if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */
|
if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */
|
||||||
bb_error_msg_and_die("%s did not send the complete time", host);
|
bb_error_msg_and_die("%s did not send the complete time", host);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
/* convert from network byte order to local byte order.
|
/* convert from network byte order to local byte order.
|
||||||
@ -70,40 +55,22 @@ static time_t askremotedate(const char *host)
|
|||||||
* the RFC 868 time 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT
|
* the RFC 868 time 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT
|
||||||
* Subtract the RFC 868 time to get Linux epoch
|
* Subtract the RFC 868 time to get Linux epoch
|
||||||
*/
|
*/
|
||||||
localt= ntohl(nett) - RFC_868_BIAS;
|
|
||||||
|
|
||||||
return(localt);
|
return(ntohl(nett) - RFC_868_BIAS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rdate_main(int argc, char **argv)
|
int rdate_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
time_t remote_time;
|
time_t remote_time;
|
||||||
int opt;
|
|
||||||
int setdate = 1;
|
|
||||||
int printdate = 1;
|
|
||||||
|
|
||||||
/* Interpret command line args */
|
unsigned long flags = bb_getopt_ulflags(argc, argv, "sp");
|
||||||
while ((opt = getopt(argc, argv, "sp")) > 0) {
|
|
||||||
switch (opt) {
|
|
||||||
case 's':
|
|
||||||
printdate = 0;
|
|
||||||
setdate = 1;
|
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
printdate = 1;
|
|
||||||
setdate = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind == argc)
|
if (!flags || argc == optind)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
|
|
||||||
remote_time = askremotedate(argv[optind]);
|
remote_time = askremotedate(argv[optind]);
|
||||||
|
|
||||||
if (setdate) {
|
if (flags & 1) {
|
||||||
time_t current_time;
|
time_t current_time;
|
||||||
|
|
||||||
time(¤t_time);
|
time(¤t_time);
|
||||||
@ -112,10 +79,10 @@ int rdate_main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
if (stime(&remote_time) < 0)
|
if (stime(&remote_time) < 0)
|
||||||
bb_perror_msg_and_die("Could not set time of day");
|
bb_perror_msg_and_die("Could not set time of day");
|
||||||
}
|
|
||||||
|
|
||||||
if (printdate)
|
/* No need to check for the -p flag as it's the only option left */
|
||||||
printf("%s", ctime(&remote_time));
|
|
||||||
|
} else printf("%s", ctime(&remote_time));
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user