diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-20 19:18:15 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-20 19:18:15 +0000 |
commit | d23f9ba0f6d82e6bab8a3ec1b804865f4b22cfb7 (patch) | |
tree | 0ab285d58cd8cf530ad8acac823545df892c90e9 /utility.c | |
parent | ef8b6c757de9684f5d88eff4b014527e87121137 (diff) | |
download | busybox-w32-d23f9ba0f6d82e6bab8a3ec1b804865f4b22cfb7.tar.gz busybox-w32-d23f9ba0f6d82e6bab8a3ec1b804865f4b22cfb7.tar.bz2 busybox-w32-d23f9ba0f6d82e6bab8a3ec1b804865f4b22cfb7.zip |
Made ps work. Fixed some stuff.
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 101 |
1 files changed, 101 insertions, 0 deletions
@@ -42,6 +42,27 @@ volatile void usage(const char *usage) | |||
42 | } | 42 | } |
43 | 43 | ||
44 | 44 | ||
45 | #if defined (BB_INIT) || defined (BB_PS) | ||
46 | |||
47 | /* Returns kernel version encoded as major*65536 + minor*256 + patch, | ||
48 | * so, for example, to check if the kernel is greater than 2.2.11: | ||
49 | * if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> } | ||
50 | */ | ||
51 | int | ||
52 | get_kernel_revision() | ||
53 | { | ||
54 | FILE *f; | ||
55 | int major=0, minor=0, patch=0; | ||
56 | |||
57 | f = fopen("/proc/sys/kernel/osrelease","r"); | ||
58 | fscanf(f,"%d.%d.%d",&major,&minor,&patch); | ||
59 | fclose(f); | ||
60 | return major*65536 + minor*256 + patch; | ||
61 | } | ||
62 | |||
63 | #endif | ||
64 | |||
65 | |||
45 | 66 | ||
46 | #if defined (BB_CP) || defined (BB_MV) | 67 | #if defined (BB_CP) || defined (BB_MV) |
47 | /* | 68 | /* |
@@ -659,4 +680,84 @@ parse_mode( const char* s, mode_t* theMode) | |||
659 | 680 | ||
660 | 681 | ||
661 | 682 | ||
683 | |||
684 | |||
685 | |||
686 | |||
687 | #if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_PS) | ||
688 | |||
689 | /* Use this to avoid needing the glibc NSS stuff | ||
690 | * This uses storage buf to hold things. | ||
691 | * */ | ||
692 | uid_t | ||
693 | my_getid(const char *filename, char *name, uid_t id) | ||
694 | { | ||
695 | FILE *stream; | ||
696 | char *rname, *start, *end, buf[128]; | ||
697 | uid_t rid; | ||
698 | |||
699 | stream=fopen(filename,"r"); | ||
700 | |||
701 | while (fgets (buf, 128, stream) != NULL) { | ||
702 | if (buf[0] == '#') | ||
703 | continue; | ||
704 | |||
705 | start = buf; | ||
706 | end = strchr (start, ':'); | ||
707 | if (end == NULL) | ||
708 | continue; | ||
709 | *end = '\0'; | ||
710 | rname = start; | ||
711 | |||
712 | start = end + 1; | ||
713 | end = strchr (start, ':'); | ||
714 | if (end == NULL) | ||
715 | continue; | ||
716 | |||
717 | start = end + 1; | ||
718 | rid = (uid_t) strtol (start, &end, 10); | ||
719 | if (end == start) | ||
720 | continue; | ||
721 | |||
722 | if (name) { | ||
723 | if (0 == strcmp(rname, name)) | ||
724 | return( rid); | ||
725 | } | ||
726 | if ( id != -1 && id == rid ) { | ||
727 | strncpy(name, rname, 8); | ||
728 | return( TRUE); | ||
729 | } | ||
730 | } | ||
731 | fclose(stream); | ||
732 | return (-1); | ||
733 | } | ||
734 | |||
735 | uid_t | ||
736 | my_getpwnam(char *name) | ||
737 | { | ||
738 | return my_getid("/etc/passwd", name, -1); | ||
739 | } | ||
740 | |||
741 | gid_t | ||
742 | my_getgrnam(char *name) | ||
743 | { | ||
744 | return my_getid("/etc/group", name, -1); | ||
745 | } | ||
746 | |||
747 | void | ||
748 | my_getpwuid(char* name, uid_t uid) | ||
749 | { | ||
750 | my_getid("/etc/passwd", name, uid); | ||
751 | } | ||
752 | |||
753 | void | ||
754 | my_getgrgid(char* group, gid_t gid) | ||
755 | { | ||
756 | my_getid("/etc/group", group, gid); | ||
757 | } | ||
758 | |||
759 | |||
760 | #endif | ||
761 | |||
762 | |||
662 | /* END CODE */ | 763 | /* END CODE */ |