Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

csh & getprogname small issue



Hi,

I do have a use case for a preloaded library that track various events
during process execution life. As part of the recorded information i
use PID, program name, timestamp, ...

It mostly works fine, but noticed that csh show a special case where
program name gets altered somehow unlike other shells :

njoly@raya [tmp/progname]> LD_PRELOAD=./libprog.so sh -c ''
init:sh
_exit:sh
njoly@raya [tmp/progname]> LD_PRELOAD=./libprog.so ksh -c ''
init:ksh
fini:ksh
_exit:ksh

njoly@raya [tmp/progname]> LD_PRELOAD=./libprog.so csh -c ''
init:csh
_exit:-sh

In the last case, when _exit(2) is called, getprogname report strange
'-sh' instead of expected 'csh'.

Is it to be expected ? This behaviour looks strange to me ...

Thanks.

NB: Attached an excerpt of the library code that illustrate the issue.
Compiled with : gcc -g -O2 -fPIC -DPIC -shared -o libprog.so prog.c

-- 
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
#include <assert.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>

static void init(void) __attribute__((__constructor__));
static void init(void) {
  printf("%s:%s\n", __func__, getprogname()); }

static void fini(void) __attribute__((__destructor__));
static void fini(void) {
  printf("%s:%s\n", __func__, getprogname()); }

static void (*o_exit)(int) = NULL;
void _exit(int status) {
  o_exit = dlsym(RTLD_NEXT, __func__);
  assert(o_exit != NULL);
  printf("%s:%s\n", __func__, getprogname());
  o_exit(status); }


Home | Main Index | Thread Index | Old Index