mirror of
https://github.com/troglobit/finit.git
synced 2026-11-11 16:40:48 +00:00
initctl: enable plain mode for ls and utmp commands
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
905c2678a3
commit
b966d031c8
2 files changed
+52
-19
No files matched your search
+27
-16
@@ -95,20 +95,28 @@ static void col_widths(void)
|
|||||||
pw = 3;
|
pw = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_header(FILE *fp, const char *line, int nl)
|
void print_header(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
|
||||||
if (plain) {
|
if (plain) {
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (!fp)
|
vfprintf(stdout, fmt, ap);
|
||||||
fp = stdout;
|
fputs("\n", stdout);
|
||||||
|
|
||||||
fprintf(fp, "%s%s\n", nl ? "\n" : "", line);
|
|
||||||
for (len = 0; len < screen_cols; len++)
|
for (len = 0; len < screen_cols; len++)
|
||||||
fputc('=', fp);
|
fputc('=', stdout);
|
||||||
fputs("\n", fp);
|
fputs("\n", stdout);
|
||||||
} else
|
} else {
|
||||||
printheader(fp, line, nl);
|
char buf[screen_cols];
|
||||||
|
|
||||||
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||||
|
printheader(stdout, buf, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int runlevel_get(int *prevlevel)
|
static int runlevel_get(int *prevlevel)
|
||||||
@@ -278,7 +286,7 @@ static int do_cond_dump(char *arg)
|
|||||||
|
|
||||||
snprintf(title, sizeof(title), "%-*s %-*s %-6s %s", pw, "PID",
|
snprintf(title, sizeof(title), "%-*s %-*s %-6s %s", pw, "PID",
|
||||||
iw, "IDENT", "STATUS", "CONDITION");
|
iw, "IDENT", "STATUS", "CONDITION");
|
||||||
print_header(NULL, title, 0);
|
print_header(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nftw(_PATH_COND, dump_one_cond, 20, 0) == -1) {
|
if (nftw(_PATH_COND, dump_one_cond, 20, 0) == -1) {
|
||||||
@@ -332,7 +340,7 @@ static int do_cond_show(char *arg)
|
|||||||
|
|
||||||
snprintf(title, sizeof(title), "%-*s %-*s %-6s %s", pw, "PID",
|
snprintf(title, sizeof(title), "%-*s %-*s %-6s %s", pw, "PID",
|
||||||
iw, "IDENT", "STATUS", "CONDITION (+ ON, ~ FLUX, - OFF)");
|
iw, "IDENT", "STATUS", "CONDITION (+ ON, ~ FLUX, - OFF)");
|
||||||
print_header(NULL, title, 0);
|
print_header(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) {
|
for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) {
|
||||||
@@ -409,15 +417,18 @@ int do_suspend (char *arg) { return do_cmd(INIT_CMD_SUSPEND); }
|
|||||||
|
|
||||||
int utmp_show(char *file)
|
int utmp_show(char *file)
|
||||||
{
|
{
|
||||||
time_t sec;
|
static int once = 0;
|
||||||
struct utmp *ut;
|
|
||||||
struct tm *sectm;
|
struct tm *sectm;
|
||||||
|
struct utmp *ut;
|
||||||
|
time_t sec;
|
||||||
|
|
||||||
int pid;
|
int pid;
|
||||||
char id[sizeof(ut->ut_id) + 1], user[sizeof(ut->ut_user) + 1], when[80];
|
char id[sizeof(ut->ut_id) + 1], user[sizeof(ut->ut_user) + 1], when[80];
|
||||||
|
|
||||||
if (heading)
|
if (heading) {
|
||||||
print_header(NULL, file, 0);
|
print_header("%s%s ", once ? "\n" : "", file);
|
||||||
|
once++;
|
||||||
|
}
|
||||||
utmpname(file);
|
utmpname(file);
|
||||||
|
|
||||||
setutent();
|
setutent();
|
||||||
@@ -560,7 +571,7 @@ static int show_status(char *arg)
|
|||||||
else
|
else
|
||||||
strlcat(title, "COMMAND", sizeof(title));
|
strlcat(title, "COMMAND", sizeof(title));
|
||||||
|
|
||||||
print_header(NULL, title, 0);
|
print_header(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) {
|
for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) {
|
||||||
|
|||||||
+25
-3
@@ -34,6 +34,10 @@
|
|||||||
|
|
||||||
extern int icreate; /* initctl -c */
|
extern int icreate; /* initctl -c */
|
||||||
extern int iforce; /* initctl -f */
|
extern int iforce; /* initctl -f */
|
||||||
|
extern int plain; /* initctl -p */
|
||||||
|
extern int heading; /* initctl -t */
|
||||||
|
|
||||||
|
extern void print_header(const char *fmt, ...);
|
||||||
|
|
||||||
|
|
||||||
static int calc_width(char *arr[], size_t len)
|
static int calc_width(char *arr[], size_t len)
|
||||||
@@ -53,7 +57,7 @@ static int calc_width(char *arr[], size_t len)
|
|||||||
|
|
||||||
static void do_list(const char *path)
|
static void do_list(const char *path)
|
||||||
{
|
{
|
||||||
char buf[screen_cols];
|
static int once = 0;
|
||||||
int width, num, prev;
|
int width, num, prev;
|
||||||
glob_t gl;
|
glob_t gl;
|
||||||
size_t i;
|
size_t i;
|
||||||
@@ -67,8 +71,26 @@ static void do_list(const char *path)
|
|||||||
if (gl.gl_pathc <= 0)
|
if (gl.gl_pathc <= 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s ", path);
|
if (plain) {
|
||||||
printheader(NULL, buf, 0);
|
if (heading)
|
||||||
|
print_header("%s%s ", once ? "\n" : "", path);
|
||||||
|
once++;
|
||||||
|
|
||||||
|
for (i = 0; i < gl.gl_pathc; i++) {
|
||||||
|
if (!heading) {
|
||||||
|
char buf[512];
|
||||||
|
|
||||||
|
paste(buf, sizeof(buf), path, gl.gl_pathv[i]);
|
||||||
|
puts(buf);
|
||||||
|
} else
|
||||||
|
puts(gl.gl_pathv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heading)
|
||||||
|
print_header("%s ", path);
|
||||||
|
|
||||||
width = calc_width(gl.gl_pathv, gl.gl_pathc);
|
width = calc_width(gl.gl_pathv, gl.gl_pathc);
|
||||||
if (width <= 0)
|
if (width <= 0)
|
||||||
|
|||||||
Reference in new issue
Block a user