diff options
Diffstat (limited to 'lib/libutil')
-rw-r--r-- | lib/libutil/libutil.h | 4 | ||||
-rw-r--r-- | lib/libutil/property.3 | 21 | ||||
-rw-r--r-- | lib/libutil/property.c | 15 | ||||
-rw-r--r-- | lib/libutil/setproctitle.c | 15 |
4 files changed, 18 insertions, 37 deletions
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h index dda01c17ad96..2aa2ad030a61 100644 --- a/lib/libutil/libutil.h +++ b/lib/libutil/libutil.h @@ -18,7 +18,7 @@ * 5. Modifications may be freely made to this file providing the above * conditions are met. * - * $Id: libutil.h,v 1.20 1998/10/09 07:32:38 jkh Exp $ + * $Id: libutil.h,v 1.19 1998/10/09 07:28:14 jkh Exp $ */ #ifndef _LIBUTIL_H_ @@ -39,7 +39,7 @@ struct winsize; struct utmp; __BEGIN_DECLS -void setproctitle __P((const char *_fmt, ...)) __printf0like(1, 2); +void setproctitle __P((const char *_fmt, ...)); void login __P((struct utmp *_ut)); int login_tty __P((int _fd)); int logout __P((char *_line)); diff --git a/lib/libutil/property.3 b/lib/libutil/property.3 index eebdde66cca0..bcd3556116e2 100644 --- a/lib/libutil/property.3 +++ b/lib/libutil/property.3 @@ -23,7 +23,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $Id: property.3,v 1.3 1998/10/14 11:04:36 jkh Exp $ +.\" $Id: property.3,v 1.2 1998/10/09 07:33:58 jkh Exp $ .\" " .Dd October 7, 1998 .Os @@ -65,7 +65,9 @@ pairs from the file descriptor passed in .Fa fd and returns the head of a new property list, assuming that the file's contents have been parsed properly, or NULL in case -of error. +of error. The property list pointer should be passed to +.Fn properties_free +when no longer needed. .Pp .Fn property_find Returns the associated value string for the property named @@ -76,22 +78,7 @@ if found, otherwise NULL. is used to free the structure returned by .Fn properties_read when it is no longer needed. -.Pp -.Sh FILE FORMAT -Each property in the file is assumed to have the format of -.Fa name = value -where -.Fa name -is an alphanumeric string (and any punctuation not including the `=' character) -and -.Fa value -is an arbitary string of text terminated by a newline character. If newlines -are desired, the entire value should be enclosed in { } (curly-bracket) -characters. Any line beginning with a # or ; character is assumed to -be a comment and will be ignored. .Sh SEE ALSO .Xr auth_getval 3 .Sh BUGS Simplistic. -.Sh AUTHOR -Jordan Hubbard diff --git a/lib/libutil/property.c b/lib/libutil/property.c index 23714a0c3daf..211450c80464 100644 --- a/lib/libutil/property.c +++ b/lib/libutil/property.c @@ -35,7 +35,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <err.h> #include <sys/types.h> #include <libutil.h> @@ -63,7 +62,7 @@ properties_read(int fd) char buf[BUFSIZ * 4]; int bp, n, v, max; enum { LOOK, COMMENT, NAME, VALUE, MVALUE, COMMIT, FILL, STOP } state; - int ch = 0, blevel = 0; + int ch = 0; n = v = bp = max = 0; head = ptr = NULL; @@ -136,10 +135,8 @@ properties_read(int fd) case VALUE: if (v == 0 && isspace(ch)) continue; - else if (ch == '{') { + else if (ch == '{') state = MVALUE; - ++blevel; - } else if (ch == '\n' || !ch) { hold_v[v] = '\0'; v = n = 0; @@ -159,20 +156,16 @@ properties_read(int fd) case MVALUE: /* multiline value */ if (v >= MAX_VALUE) { - warn("properties_read: value exceeds max length"); state = COMMENT; n = v = 0; } - else if (ch == '}' && !--blevel) { + else if (ch == '}') { hold_v[v] = '\0'; v = n = 0; state = COMMIT; } - else { + else hold_v[v++] = ch; - if (ch == '{') - ++blevel; - } break; case COMMIT: diff --git a/lib/libutil/setproctitle.c b/lib/libutil/setproctitle.c index 3bce42074da8..217df06ac8c0 100644 --- a/lib/libutil/setproctitle.c +++ b/lib/libutil/setproctitle.c @@ -14,7 +14,7 @@ * 3. Absolutely no warranty of function or purpose is made by the author * Peter Wemm. * - * $Id: setproctitle.c,v 1.7 1998/04/28 07:02:33 dg Exp $ + * $Id: setproctitle.c,v 1.6 1998/04/28 06:59:14 dg Exp $ */ #include <sys/types.h> @@ -72,8 +72,8 @@ setproctitle(fmt, va_alist) static char buf[SPT_BUFSIZE]; static char *ps_argv[2]; va_list ap; + int mib[2]; size_t len; - unsigned long ul_ps_strings; #if defined(__STDC__) va_start(ap, fmt); @@ -104,11 +104,12 @@ setproctitle(fmt, va_alist) va_end(ap); if (ps_strings == NULL) { - len = sizeof(ul_ps_strings); - if (sysctlbyname("kern.ps_strings", &ul_ps_strings, &len, NULL, - 0) == -1) - ul_ps_strings = PS_STRINGS; - ps_strings = (struct ps_strings *)ul_ps_strings; + mib[0] = CTL_KERN; + mib[1] = KERN_PS_STRINGS; + len = sizeof(ps_strings); + if (sysctl(mib, 2, &ps_strings, &len, NULL, 0) < 0 || + ps_strings == NULL) + ps_strings = PS_STRINGS; } /* PS_STRINGS points to zeroed memory on a style #2 kernel */ |