2008-09-07 01:48:05 +03:00
|
|
|
/* -*- Mode: C -*- */
|
|
|
|
/*
|
|
|
|
* LASH
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This implementation should work on Linux, on FreeBSD we could use setprotitile(3) */
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2009-07-12 22:56:19 +03:00
|
|
|
#include "../common/debug.h"
|
2008-09-07 01:48:05 +03:00
|
|
|
|
|
|
|
static char * g_argv_begin;
|
|
|
|
static char * g_argv_end;
|
|
|
|
|
|
|
|
void
|
|
|
|
lash_init_setproctitle(
|
2009-07-13 00:15:44 +03:00
|
|
|
int argc,
|
|
|
|
char ** argv,
|
|
|
|
char ** envp)
|
2008-09-07 01:48:05 +03:00
|
|
|
{
|
2009-07-13 00:15:44 +03:00
|
|
|
char * last_arg;
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-07-13 00:15:44 +03:00
|
|
|
g_argv_begin = argv[0];
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-07-13 00:15:44 +03:00
|
|
|
last_arg = argv[argc-1];
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-07-13 00:15:44 +03:00
|
|
|
g_argv_end = last_arg + strlen(last_arg);
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-07-13 00:15:44 +03:00
|
|
|
//lash_info("%u chars available for title", g_argv_end - g_argv_begin);
|
2008-09-07 01:48:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lash_setproctitile(
|
2009-07-13 00:15:44 +03:00
|
|
|
const char * format,
|
|
|
|
...)
|
2008-09-07 01:48:05 +03:00
|
|
|
{
|
2009-07-13 00:15:44 +03:00
|
|
|
va_list ap;
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-07-13 00:15:44 +03:00
|
|
|
va_start(ap, format);
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-07-13 00:15:44 +03:00
|
|
|
memset(g_argv_begin, 0, g_argv_end - g_argv_begin);
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-07-13 00:15:44 +03:00
|
|
|
vsnprintf(g_argv_begin, g_argv_end - g_argv_begin, format, ap);
|
2008-09-07 01:48:05 +03:00
|
|
|
|
2009-07-13 00:15:44 +03:00
|
|
|
va_end(ap);
|
2008-09-07 01:48:05 +03:00
|
|
|
}
|