diff options
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/dutmp.c | 47 | ||||
| -rw-r--r-- | miscutils/makedevs.c | 95 | ||||
| -rw-r--r-- | miscutils/mt.c | 98 | ||||
| -rw-r--r-- | miscutils/update.c | 48 |
4 files changed, 288 insertions, 0 deletions
diff --git a/miscutils/dutmp.c b/miscutils/dutmp.c new file mode 100644 index 000000000..e92b6700f --- /dev/null +++ b/miscutils/dutmp.c | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | /* | ||
| 2 | * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> | ||
| 3 | * | ||
| 4 | * dutmp | ||
| 5 | * Takes utmp formated file on stdin and dumps it's contents | ||
| 6 | * out in colon delimited fields. Easy to 'cut' for shell based | ||
| 7 | * versions of 'who', 'last', etc. IP Addr is output in hex, | ||
| 8 | * little endian on x86. | ||
| 9 | * | ||
| 10 | * made against libc6 | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "internal.h" | ||
| 14 | #include <stdio.h> | ||
| 15 | #include <utmp.h> | ||
| 16 | |||
| 17 | const char dutmp_usage[] = "dutmp\n" | ||
| 18 | "\n" | ||
| 19 | "\tDump file or stdin utmp file format to stdout, pipe delimited.\n" | ||
| 20 | "\tdutmp /var/run/utmp\n"; | ||
| 21 | |||
| 22 | extern int | ||
| 23 | dutmp_fn(const struct FileInfo * i) | ||
| 24 | { | ||
| 25 | |||
| 26 | FILE * f = stdin; | ||
| 27 | struct utmp * ut = (struct utmp *) malloc(sizeof(struct utmp) ); | ||
| 28 | |||
| 29 | if ( i ) | ||
| 30 | if (! (f = fopen(i->source, "r"))) { | ||
| 31 | name_and_error(i->source); | ||
| 32 | return 1; | ||
| 33 | } | ||
| 34 | |||
| 35 | while (fread (ut, 1, sizeof(struct utmp), f)) { | ||
| 36 | //printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n", | ||
| 37 | printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", | ||
| 38 | ut->ut_type, ut->ut_pid, ut->ut_line, | ||
| 39 | ut->ut_id, ut->ut_user, ut->ut_host, | ||
| 40 | ut->ut_exit.e_termination, ut->ut_exit.e_exit, | ||
| 41 | ut->ut_session, | ||
| 42 | ut->ut_tv.tv_sec, ut->ut_tv.tv_usec, | ||
| 43 | ut->ut_addr); | ||
| 44 | } | ||
| 45 | |||
| 46 | return 0; | ||
| 47 | } | ||
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c new file mode 100644 index 000000000..691236e29 --- /dev/null +++ b/miscutils/makedevs.c | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | /* | ||
| 2 | * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> | ||
| 3 | * | ||
| 4 | * makedevs | ||
| 5 | * Make ranges of device files quickly. | ||
| 6 | * known bugs: can't deal with alpha ranges | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "internal.h" | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <string.h> | ||
| 13 | #include <fcntl.h> | ||
| 14 | #include <unistd.h> | ||
| 15 | #include <sys/types.h> | ||
| 16 | #include <sys/stat.h> | ||
| 17 | |||
| 18 | const char makedevs_usage[] = | ||
| 19 | "makedevs 0.01 -- Create an entire range of device files\n\n" | ||
| 20 | "\tmakedevs /dev/ttyS c 4 64 0 63 (ttyS0-ttyS63)\n" | ||
| 21 | "\tmakedevs /dev/hda b 3 0 0 8 s (hda,hda1-hda8)\n"; | ||
| 22 | |||
| 23 | int | ||
| 24 | makedevs_main(struct FileInfo * i, int argc, char * * argv) | ||
| 25 | { | ||
| 26 | |||
| 27 | const char *basedev = argv[1]; | ||
| 28 | const char *type = argv[2]; | ||
| 29 | int major = atoi(argv[3]); | ||
| 30 | int Sminor = atoi(argv[4]); | ||
| 31 | int S = atoi(argv[5]); | ||
| 32 | int E = atoi(argv[6]); | ||
| 33 | int sbase = argc == 8 ? 1 : 0; | ||
| 34 | |||
| 35 | mode_t mode = 0; | ||
| 36 | dev_t dev = 0; | ||
| 37 | char devname[255]; | ||
| 38 | char buf[255]; | ||
| 39 | |||
| 40 | switch (type[0]) { | ||
| 41 | case 'c': | ||
| 42 | mode = S_IFCHR; break; | ||
| 43 | case 'b': | ||
| 44 | mode = S_IFBLK; break; | ||
| 45 | case 'f': | ||
| 46 | mode = S_IFIFO; break; | ||
| 47 | default: | ||
| 48 | usage(makedevs_usage); | ||
| 49 | return 2; | ||
| 50 | } | ||
| 51 | mode |= 0660; | ||
| 52 | |||
| 53 | while ( S <= E ) { | ||
| 54 | |||
| 55 | if (type[0] != 'f') | ||
| 56 | dev = (major << 8) | Sminor; | ||
| 57 | strcpy(devname, basedev); | ||
| 58 | |||
| 59 | if (sbase == 0) { | ||
| 60 | sprintf(buf, "%d", S); | ||
| 61 | strcat(devname, buf); | ||
| 62 | } else { | ||
| 63 | sbase = 0; | ||
| 64 | } | ||
| 65 | |||
| 66 | if (mknod (devname, mode, dev)) | ||
| 67 | printf("Failed to create: %s\n", devname); | ||
| 68 | |||
| 69 | S++; Sminor++; | ||
| 70 | } | ||
| 71 | |||
| 72 | return 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | /* | ||
| 76 | And this is what this program replaces. The shell is too slow! | ||
| 77 | |||
| 78 | makedev () { | ||
| 79 | local basedev=$1; local S=$2; local E=$3 | ||
| 80 | local major=$4; local Sminor=$5; local type=$6 | ||
| 81 | local sbase=$7 | ||
| 82 | |||
| 83 | if [ ! "$sbase" = "" ]; then | ||
| 84 | mknod "$basedev" $type $major $Sminor | ||
| 85 | S=`expr $S + 1` | ||
| 86 | Sminor=`expr $Sminor + 1` | ||
| 87 | fi | ||
| 88 | |||
| 89 | while [ $S -le $E ]; do | ||
| 90 | mknod "$basedev$S" $type $major $Sminor | ||
| 91 | S=`expr $S + 1` | ||
| 92 | Sminor=`expr $Sminor + 1` | ||
| 93 | done | ||
| 94 | } | ||
| 95 | */ | ||
diff --git a/miscutils/mt.c b/miscutils/mt.c new file mode 100644 index 000000000..7d75fbd3d --- /dev/null +++ b/miscutils/mt.c | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | #include "internal.h" | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <sys/mtio.h> | ||
| 4 | #include <sys/fcntl.h> | ||
| 5 | |||
| 6 | const char mt_usage[] = "mt [-f device] opcode value\n"; | ||
| 7 | |||
| 8 | struct mt_opcodes { | ||
| 9 | char * name; | ||
| 10 | short value; | ||
| 11 | }; | ||
| 12 | |||
| 13 | /* missing: eod/seod, stoptions, stwrthreshold, densities */ | ||
| 14 | static const struct mt_opcodes opcodes[] = { | ||
| 15 | { "bsf", MTBSF }, | ||
| 16 | { "bsfm", MTBSFM }, | ||
| 17 | { "bsr", MTBSR }, | ||
| 18 | { "bss", MTBSS }, | ||
| 19 | { "datacompression", MTCOMPRESSION }, | ||
| 20 | { "eom", MTEOM }, | ||
| 21 | { "erase", MTERASE }, | ||
| 22 | { "fsf", MTFSF }, | ||
| 23 | { "fsfm", MTFSFM }, | ||
| 24 | { "fsr", MTFSR }, | ||
| 25 | { "fss", MTFSS }, | ||
| 26 | { "load", MTLOAD }, | ||
| 27 | { "lock", MTLOCK }, | ||
| 28 | { "mkpart", MTMKPART }, | ||
| 29 | { "nop", MTNOP }, | ||
| 30 | { "offline",MTOFFL }, | ||
| 31 | { "rewoffline",MTOFFL }, | ||
| 32 | { "ras1", MTRAS1 }, | ||
| 33 | { "ras2", MTRAS2 }, | ||
| 34 | { "ras3", MTRAS3 }, | ||
| 35 | { "reset", MTRESET }, | ||
| 36 | { "retension", MTRETEN }, | ||
| 37 | { "rew", MTREW }, | ||
| 38 | { "seek", MTSEEK }, | ||
| 39 | { "setblk", MTSETBLK }, | ||
| 40 | { "setdensity", MTSETDENSITY }, | ||
| 41 | { "drvbuffer", MTSETDRVBUFFER }, | ||
| 42 | { "setpart", MTSETPART }, | ||
| 43 | { "tell", MTTELL }, | ||
| 44 | { "wset", MTWSM }, | ||
| 45 | { "unload", MTUNLOAD }, | ||
| 46 | { "unlock", MTUNLOCK }, | ||
| 47 | { "eof", MTWEOF }, | ||
| 48 | { "weof", MTWEOF }, | ||
| 49 | { 0, 0 } | ||
| 50 | }; | ||
| 51 | |||
| 52 | extern int | ||
| 53 | mt_main(struct FileInfo * i, int argc, char * * argv) | ||
| 54 | { | ||
| 55 | const char * file = "/dev/tape"; | ||
| 56 | const struct mt_opcodes * code = opcodes; | ||
| 57 | struct mtop op; | ||
| 58 | int fd; | ||
| 59 | |||
| 60 | if ( strcmp(argv[1], "-f") == 0 ) { | ||
| 61 | if ( argc < 4 ) { | ||
| 62 | usage(mt_usage); | ||
| 63 | return 1; | ||
| 64 | } | ||
| 65 | file = argv[2]; | ||
| 66 | argv += 2; | ||
| 67 | argc -= 2; | ||
| 68 | } | ||
| 69 | |||
| 70 | while ( code->name != 0 ) { | ||
| 71 | if ( strcmp(code->name, argv[1]) == 0 ) | ||
| 72 | break; | ||
| 73 | code++; | ||
| 74 | } | ||
| 75 | |||
| 76 | if ( code->name == 0 ) { | ||
| 77 | fprintf(stderr, "mt: unrecognized opcode %s.\n", argv[1]); | ||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | op.mt_op = code->value; | ||
| 82 | if ( argc >= 3 ) | ||
| 83 | op.mt_count = atoi(argv[2]); | ||
| 84 | else | ||
| 85 | op.mt_count = 1; /* One, not zero, right? */ | ||
| 86 | |||
| 87 | if ( (fd = open(file, O_RDONLY, 0)) < 0 ) { | ||
| 88 | name_and_error(file); | ||
| 89 | return 1; | ||
| 90 | } | ||
| 91 | |||
| 92 | if ( ioctl(fd, MTIOCTOP, &op) != 0 ) { | ||
| 93 | name_and_error(file); | ||
| 94 | return 1; | ||
| 95 | } | ||
| 96 | |||
| 97 | return 0; | ||
| 98 | } | ||
diff --git a/miscutils/update.c b/miscutils/update.c new file mode 100644 index 000000000..f3b7fc0c8 --- /dev/null +++ b/miscutils/update.c | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | #include "internal.h" | ||
| 2 | #include <linux/unistd.h> | ||
| 3 | |||
| 4 | const char update_usage[] = "update\n" | ||
| 5 | "\n" | ||
| 6 | "\tFlush buffered data to the disk devices every 30 seconds.\n"; | ||
| 7 | |||
| 8 | #if defined(__GLIBC__) | ||
| 9 | #include <sys/kdaemon.h> | ||
| 10 | #else | ||
| 11 | _syscall2(int, bdflush, int, func, int, data); | ||
| 12 | #endif /* __GLIBC__ */ | ||
| 13 | |||
| 14 | extern int | ||
| 15 | update_main(struct FileInfo * i, int argc, char * * argv) | ||
| 16 | { | ||
| 17 | /* | ||
| 18 | * Update is actually two daemons, bdflush and update. | ||
| 19 | */ | ||
| 20 | int pid; | ||
| 21 | |||
| 22 | pid = fork(); | ||
| 23 | if ( pid < 0 ) | ||
| 24 | return pid; | ||
| 25 | else if ( pid == 0 ) { | ||
| 26 | /* | ||
| 27 | * This is no longer necessary since 1.3.5x, but it will harmlessly | ||
| 28 | * exit if that is the case. | ||
| 29 | */ | ||
| 30 | strcpy(argv[0], "bdflush (update)"); | ||
| 31 | argv[1] = 0; | ||
| 32 | argv[2] = 0; | ||
| 33 | bdflush(1, 0); | ||
| 34 | _exit(0); | ||
| 35 | } | ||
| 36 | pid = fork(); | ||
| 37 | if ( pid < 0 ) | ||
| 38 | return pid; | ||
| 39 | else if ( pid == 0 ) { | ||
| 40 | argv[0] = "update"; | ||
| 41 | for ( ; ; ) { | ||
| 42 | sync(); | ||
| 43 | sleep(30); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | return 0; | ||
| 48 | } | ||
