2009-07-29 21:08:27 +03:00
|
|
|
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
2008-09-07 01:48:05 +03:00
|
|
|
/*
|
2009-07-29 21:08:27 +03:00
|
|
|
* LADI Session Handler (ladish)
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-09-20 18:02:10 +03:00
|
|
|
* Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-07-29 21:08:27 +03:00
|
|
|
**************************************************************************
|
|
|
|
* This file contains the code that sets process "title"
|
|
|
|
**************************************************************************
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-07-29 21:08:27 +03:00
|
|
|
* LADI Session Handler 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.
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-07-29 21:08:27 +03:00
|
|
|
* LADI Session Handler 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 LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
* or write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-09-07 01:48:05 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* This implementation should work on Linux, on FreeBSD we could use setprotitile(3) */
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2009-09-20 18:02:10 +03:00
|
|
|
#include "../log.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
|
|
|
}
|