dslinux/user/sysutils df.c free.c hostname.c kill.c Makefile ps.c reboot.c shutdown.c
amadeus
dslinux_amadeus at user.in-berlin.de
Thu Aug 31 10:04:34 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/sysutils
In directory antilope:/tmp/cvs-serv27555/user/sysutils
Modified Files:
ps.c
Added Files:
df.c free.c hostname.c kill.c Makefile reboot.c shutdown.c
Log Message:
Adding sysutils to HEAD
--- NEW FILE: free.c ---
/* free.c:
*
* Copyright (C) 1998 Kenneth Albanowski <kjahds at kjahds.com>,
* Copyright (C) 1999 D. Jeff Dionne <jeff at lineo.ca>
* Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
*
* This program is free software; you can redistribute it and/or modify
* 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.
*/
#include <linux/autoconf.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
char buf[256];
int
main(argc, argv)
char **argv;
{
int i;
FILE * f;
f = fopen("/proc/meminfo", "r");
if (!f) {
perror("Unable to open /proc/meminfo: ");
exit(1);
}
for(i=0;i<3;i++) {
fgets(buf, 250, f);
fputs(buf, stdout);
}
fclose(f);
exit(0);
}
Index: ps.c
===================================================================
RCS file: /cvsroot/dslinux/dslinux/user/sysutils/ps.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ps.c 21 May 2005 13:17:23 -0000 1.2
+++ ps.c 31 Aug 2006 08:04:32 -0000 1.3
@@ -305,8 +305,7 @@
pcpu / 10, pcpu % 10,
/*(int)seconds / 60, (int)seconds % 60,*/
l ? psbuf : name);
- next:
- ;
+ next: ;
}
closedir(d);
--- NEW FILE: shutdown.c ---
/* shutdown.c:
*
* Copyright (C) 1998 Kenneth Albanowski <kjahds at kjahds.com>,
* Copyright (C) 1999 D. Jeff Dionne <jeff at lineo.ca>
* Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
*
* This program is free software; you can redistribute it and/or modify
* 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.
*/
#include <linux/autoconf.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <signal.h>
#if __GNU_LIBRARY__ > 5
#include <sys/reboot.h>
#endif
int
main(argc, argv)
int argc;
char **argv;
{
if ((argc != 3) || (strcmp(argv[1], "-h") && strcmp(argv[1], "-r")) || strcmp(argv[2], "now")) {
printf("Usage: %s -h|-r now\n", argv[0]);
exit(0);
}
kill(1, SIGTSTP);
sync();
signal(SIGTERM,SIG_IGN);
setpgrp();
kill(-1, SIGTERM);
sleep(1);
kill(-1, SIGHUP); /* Force PPPD's down, too */
sleep(1);
kill(-1, SIGKILL);
sync();
sleep(1);
if (strcmp(argv[1], "-h")==0) {
#if __GNU_LIBRARY__ > 5
reboot(0xCDEF0123);
#else
reboot(0xfee1dead, 672274793, 0xCDEF0123);
#endif
} else {
#if __GNU_LIBRARY__ > 5
reboot(0x01234567);
#else
reboot(0xfee1dead, 672274793, 0x01234567);
#endif
}
exit(0); /* Shrug */
}
--- NEW FILE: reboot.c ---
/* shutdown.c:
*
* Copyright (C) 1998 Kenneth Albanowski <kjahds at kjahds.com>,
*
* This program is free software; you can redistribute it and/or modify
* 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.
*
* JUN/99 -- copied from shutdown.c to make new reboot command.
* (gerg at snapgear.com)
* AUG/99 -- added delay option to reboot
*/
#include <linux/autoconf.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <signal.h>
#include <getopt.h>
#if __GNU_LIBRARY__ > 5
#include <sys/reboot.h>
#endif
int main(int argc, char *argv[])
{
int delay = 0; /* delay in seconds before rebooting */
int rc;
while ((rc = getopt(argc, argv, "h?d:")) > 0) {
switch (rc) {
case 'd':
delay = atoi(optarg);
break;
case 'h':
case '?':
default:
printf("usage: reboot [-h] [-d <delay>]\n");
exit(0);
break;
}
}
if(delay > 0)
sleep(delay);
kill(1, SIGTSTP);
sync();
signal(SIGTERM,SIG_IGN);
setpgrp();
kill(-1, SIGTERM);
kill(-1, SIGHUP);
sleep(1);
kill(-1, SIGKILL);
sync();
sleep(1);
#if __GNU_LIBRARY__ > 5
reboot(0x01234567);
#else
reboot(0xfee1dead, 672274793, 0x01234567);
#endif
exit(0); /* Shrug */
}
--- NEW FILE: df.c ---
/* df.c:
*
* Copyright (C) 1998 Kenneth Albanowski <kjahds at kjahds.com>
* Copyright (C) 1999 D. Jeff Dionne <jeff at lineo.ca>
* Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
*
* This program is free software; you can redistribute it and/or modify
* 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.
*/
#include <linux/autoconf.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <linux/major.h>
#include <linux/types.h>
#include <sys/time.h>
#include <asm/param.h>
#include <errno.h>
int
main(int argc, char * argv[])
{
char * name;
struct statfs stbuf;
fclose(stdin);
if (argc<2)
name = "/";
else
name = argv[1];
if (statfs(name, &stbuf) == -1) {
printf("Unable to get disk space of %s: %s\n", name, strerror(errno));
exit(1);
}
printf("Total bytes: %ld\n", stbuf.f_bsize * stbuf.f_blocks);
printf("Free bytes: %ld\n", stbuf.f_bsize * stbuf.f_bfree);
printf("Total nodes: %ld\n", stbuf.f_files);
printf("Free nodes: %ld\n", stbuf.f_ffree);
exit(0);
}
--- NEW FILE: Makefile ---
EXECS = kill ps df shutdown free hostname reboot
OBJS = kill.o ps.o df.o shutdown.o free.o hostname.o reboot.o
all: $(EXECS)
$(EXECS): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $@.o $(LDLIBS)
romfs:
$(ROMFSINST) -e CONFIG_USER_SYSUTILS_DF /bin/df
$(ROMFSINST) -e CONFIG_USER_SYSUTILS_FREE /bin/free
$(ROMFSINST) -e CONFIG_USER_SYSUTILS_HOSTNAME /bin/hostname
$(ROMFSINST) -e CONFIG_USER_SYSUTILS_KILL /bin/kill
$(ROMFSINST) -e CONFIG_USER_SYSUTILS_PS /bin/ps
$(ROMFSINST) -e CONFIG_USER_SYSUTILS_REBOOT /bin/reboot
$(ROMFSINST) -e CONFIG_USER_SYSUTILS_SHUTDOWN /bin/shutdown
clean:
rm -f $(EXECS) *.elf *.gdb *.o
--- NEW FILE: hostname.c ---
/* hostname.c - poe at daimi.aau.dk */
#include <sys/types.h>
#include <sys/param.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
char hn[MAXHOSTNAMELEN + 1];
if(argc >= 2) {
if(geteuid() || getuid()) {
puts("You must be root to change the hostname");
exit(1);
}
if(strlen(argv[1]) > MAXHOSTNAMELEN) {
puts("That name is too long.");
exit(1);
}
sethostname(argv[1], strlen(argv[1]));
} else {
gethostname(hn, MAXHOSTNAMELEN);
puts(hn);
}
exit(0);
}
--- NEW FILE: kill.c ---
/* kill.c
*
* Copyright (c) 1993 by David I. Bell
* Copyright (C) 1999, Rt-Control Inc.
* Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
*
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <pwd.h>
#include <grp.h>
#include <utime.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifndef isdecimal
#define isdecimal(X) ((X) >= '0' && (X) <= '9' ? 1 : 0)
#endif
int
main(argc, argv)
char **argv;
{
char *cp;
int sig;
int pid;
sig = SIGTERM;
if (argv[1][0] == '-') {
cp = &argv[1][1];
if (strcmp(cp, "HUP") == 0)
sig = SIGHUP;
else if (strcmp(cp, "INT") == 0)
sig = SIGINT;
else if (strcmp(cp, "QUIT") == 0)
sig = SIGQUIT;
else if (strcmp(cp, "ILL") == 0)
sig = SIGILL;
else if (strcmp(cp, "TRAP") == 0)
sig = SIGTRAP;
else if (strcmp(cp, "ABRT") == 0)
sig = SIGABRT;
else if (strcmp(cp, "IOT") == 0)
sig = SIGIOT;
else if (strcmp(cp, "BUS") == 0)
sig = SIGBUS;
else if (strcmp(cp, "FPE") == 0)
sig = SIGFPE;
else if (strcmp(cp, "KILL") == 0)
sig = SIGKILL;
else if (strcmp(cp, "USR1") == 0)
sig = SIGUSR1;
else if (strcmp(cp, "SEGV") == 0)
sig = SIGSEGV;
else if (strcmp(cp, "USR2") == 0)
sig = SIGUSR2;
else if (strcmp(cp, "PIPE") == 0)
sig = SIGPIPE;
else if (strcmp(cp, "ALRM") == 0)
sig = SIGALRM;
else if (strcmp(cp, "TERM") == 0)
sig = SIGTERM;
else if (strcmp(cp, "STKFLT") == 0)
sig = SIGSTKFLT;
else if (strcmp(cp, "CHLD") == 0)
sig = SIGCHLD;
else if (strcmp(cp, "CONT") == 0)
sig = SIGCONT;
else if (strcmp(cp, "STOP") == 0)
sig = SIGSTOP;
else if (strcmp(cp, "TSTP") == 0)
sig = SIGTSTP;
else if (strcmp(cp, "TTIN") == 0)
sig = SIGTTIN;
else if (strcmp(cp, "TTOU") == 0)
sig = SIGTTOU;
else if (strcmp(cp, "URG") == 0)
sig = SIGURG;
else if (strcmp(cp, "PWR") == 0)
sig = SIGPWR;
else {
sig = 0;
while (isdecimal(*cp))
sig = sig * 10 + *cp++ - '0';
if (*cp) {
write(2, "Unknown signal\n", strlen("Unknown signal\n"));
exit(1);
}
}
argc--;
argv++;
}
while (argc-- > 1) {
cp = *++argv;
pid = 0;
while (isdecimal(*cp))
pid = pid * 10 + *cp++ - '0';
if (*cp) {
write(2, "Non-numeric pid\n", strlen("Non-numeric pid\n"));
exit(1);
}
if (kill(pid, sig) < 0)
perror(*argv);
}
return 0;
}
More information about the dslinux-commit
mailing list