-# $OpenBSD: Makefile,v 1.16 2014/07/16 20:06:27 okan Exp $
+# $OpenBSD: Makefile,v 1.17 2018/09/22 16:50:35 millert Exp $
#
# Makefile for OpenBSD top-3.4.
PROG= top
CFLAGS+=-I. -Wall -Wmissing-prototypes
-SRCS= commands.c display.c machine.c screen.c top.c username.c utils.c
+SRCS= commands.c display.c machine.c screen.c top.c utils.c
DPADD= ${LIBCURSES}
LDADD= -lcurses
-/* $OpenBSD: machine.c,v 1.91 2018/09/13 15:23:32 millert Exp $ */
+/* $OpenBSD: machine.c,v 1.92 2018/09/22 16:50:35 millert Exp $ */
/*-
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
}
char *
-format_next_process(caddr_t hndl, const char *(*get_userid)(uid_t), pid_t *pid,
- int show_threads)
+format_next_process(caddr_t hndl, const char *(*get_userid)(uid_t, int),
+ pid_t *pid, int show_threads)
{
char *p_wait;
struct kinfo_proc *pp;
if (show_threads)
snprintf(buf, sizeof(buf), "%8d", pp->p_tid);
else
- snprintf(buf, sizeof(buf), "%s", (*get_userid)(pp->p_ruid));
+ snprintf(buf, sizeof(buf), "%s", (*get_userid)(pp->p_ruid, 0));
/* format this entry */
snprintf(fmt, sizeof(fmt), Proc_format, pp->p_pid, buf,
-/* $OpenBSD: machine.h,v 1.21 2018/09/13 15:23:32 millert Exp $ */
+/* $OpenBSD: machine.h,v 1.22 2018/09/22 16:50:35 millert Exp $ */
/*
* Top users/processes display for Unix
extern caddr_t
get_process_info(struct system_info *, struct process_select *,
int (*) (const void *, const void *));
-extern char *format_next_process(caddr_t, const char *(*)(uid_t), pid_t *, int);
+extern char *format_next_process(caddr_t, const char *(*)(uid_t, int), pid_t *, int);
extern uid_t proc_owner(pid_t);
extern struct kinfo_proc *getprocs(int, int, int *);
-/* $OpenBSD: top.c,v 1.91 2018/09/13 15:23:32 millert Exp $ */
+/* $OpenBSD: top.c,v 1.92 2018/09/22 16:50:35 millert Exp $ */
/*
* Top users/processes display for Unix
#include <signal.h>
#include <string.h>
#include <poll.h>
+#include <pwd.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
case 'U': /* display only username's processes */
if (optarg[0] == '-') {
- if ((ps.huid = userid(optarg+1)) == (uid_t)-1)
- new_message(MT_delayed, "%s: unknown user",
- optarg);
+ if (uid_from_user(optarg+1, &ps.huid) == -1)
+ new_message(MT_delayed,
+ "%s: unknown user", optarg);
else
ps.uid = (uid_t)-1;
- } else if ((ps.uid = userid(optarg)) == (uid_t)-1)
+ } else if (uid_from_user(optarg, &ps.uid) == -1)
new_message(MT_delayed, "%s: unknown user",
optarg);
else
main(int argc, char *argv[])
{
char *uname_field = "USERNAME", *header_text, *env_top;
- const char *(*get_userid)(uid_t) = username;
+ const char *(*get_userid)(uid_t, int) = user_from_uid;
char **preset_argv = NULL, **av = argv;
int preset_argc = 0, ac = argc, active_procs, i;
sigset_t mask, oldmask;
char ch, *iptr;
int change, i;
struct pollfd pfd[1];
- uid_t uid, huid;
static char command_chars[] = "\f qh?en#sdkriIuSopCHg+P1";
/*
ps.uid = (uid_t)-1;
ps.huid = (uid_t)-1;
} else if (tempbuf[0] == '-') {
- if ((huid = userid(tempbuf+1)) == (uid_t)-1) {
+ if (uid_from_user(tempbuf+1, &ps.huid) == -1) {
new_message(MT_standout,
" %s: unknown user", tempbuf+1);
no_command = Yes;
} else {
- ps.huid = huid;
ps.uid = (uid_t)-1;
}
- } else if ((uid = userid(tempbuf)) == (uid_t)-1) {
+ } else if (uid_from_user(tempbuf, &ps.uid) == -1) {
new_message(MT_standout,
" %s: unknown user", tempbuf);
no_command = Yes;
} else {
- ps.uid = uid;
ps.huid = (uid_t)-1;
}
putr();
-/* $OpenBSD: top.h,v 1.17 2018/09/16 17:37:11 krw Exp $ */
+/* $OpenBSD: top.h,v 1.18 2018/09/22 16:50:35 millert Exp $ */
/*
* Top users/processes display for Unix
/* top.c */
extern void quit(int);
-
-/* username.c */
-extern const char *username(uid_t);
-extern uid_t userid(const char *);
+++ /dev/null
-/* $OpenBSD: username.c,v 1.20 2018/09/22 02:18:19 procter Exp $ */
-
-/*
- * Top users/processes display for Unix
- * Version 3
- *
- * Copyright (c) 1984, 1989, William LeFebvre, Rice University
- * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR OR HIS EMPLOYER BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Username translation code for top.
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <pwd.h>
-
-#include "top.local.h"
-#include "top.h"
-#include "utils.h"
-
-const char *
-username(uid_t uid)
-{
- return user_from_uid(uid, 0);
-}
-
-uid_t
-userid(const char *username)
-{
- uid_t uid;
- if (uid_from_user(username, &uid) == -1) {
- uid = (uid_t)-1;
- }
- return uid;
-}
-/* $OpenBSD: utils.c,v 1.27 2018/09/13 15:23:32 millert Exp $ */
+/* $OpenBSD: utils.c,v 1.28 2018/09/22 16:50:35 millert Exp $ */
/*
* Top users/processes display for Unix
* justified in a 6 character field to match uname_field in top.c.
*/
const char *
-format_uid(uid_t uid)
+format_uid(uid_t uid, int nouser)
{
static char buffer[16]; /* result is built here */
-/* $OpenBSD: utils.h,v 1.9 2018/09/13 15:23:32 millert Exp $ */
+/* $OpenBSD: utils.h,v 1.10 2018/09/22 16:50:35 millert Exp $ */
/*
* Top users/processes display for Unix
int atoiwi(char *);
char *itoa(int);
-const char *format_uid(uid_t);
+const char *format_uid(uid_t, int);
int digits(int);
int string_index(char *, char **);
char **argparse(char *, int *);