5 #include <sys/socket.h>
7 #define UNIX_PATH_MAX 108
9 //#define SOCKETDIR "/var/run/ust/socks"
10 #define SOCKETDIR "/tmp/socks"
11 #define SOCKETDIRLEN sizeof(SOCKETDIR)
12 #define USTSIGNAL SIGIO
14 #define DBG(fmt, args...) fprintf(stderr, fmt "\n", ## args)
15 #define WARN(fmt, args...) fprintf(stderr, "usertrace: WARNING: " fmt "\n", ## args)
16 #define ERR(fmt, args...) fprintf(stderr, "usertrace: ERROR: " fmt "\n", ## args)
17 #define PERROR(call) perror("usertrace: ERROR: " call)
19 struct tracecmd
{ /* no padding */
26 char mysocketfile
[UNIX_PATH_MAX
] = "";
28 void do_command(struct tracecmd
*cmd
)
32 void receive_commands()
36 /* The signal handler itself. */
38 void sighandler(int sig
)
44 /* Called by the app signal handler to chain it to us. */
48 sighandler(USTSIGNAL
);
58 struct sockaddr_un addr
;
60 result
= fd
= socket(PF_UNIX
, SOCK_SEQPACKET
, 0);
66 addr
.sun_family
= AF_UNIX
;
68 result
= snprintf(addr
.sun_path
, UNIX_PATH_MAX
, "%s/%d", SOCKETDIR
, mypid
);
69 if(result
>= UNIX_PATH_MAX
) {
70 ERR("string overflow allocating socket name");
73 //DBG("opening socket at %s", addr.sun_path);
75 result
= bind(fd
, (struct sockaddr
*)&addr
, sizeof(addr
));
81 strcpy(mysocketfile
, addr
.sun_path
);
93 if(mysocketfile
[0] == '\0')
96 result
= unlink(mysocketfile
);
102 int init_signal_handler(void)
104 /* Attempt to handler SIGIO. If the main program wants to
105 * handle it, fine, it'll override us. They it'll have to
106 * use the chaining function.
110 struct sigaction act
;
112 result
= sigemptyset(&act
.sa_mask
);
114 PERROR("sigemptyset");
118 act
.sa_handler
= sighandler
;
119 act
.sa_flags
= SA_RESTART
;
121 /* Only defer ourselves. Also, try to restart interrupted
122 * syscalls to disturb the traced program as little as possible.
124 result
= sigaction(SIGIO
, &act
, NULL
);
133 void __attribute__((constructor
)) init()
139 /* if using instead seperate thread, then should create thread */
140 result
= init_signal_handler();
141 result
= init_socket();
145 /* should decrementally destroy stuff if error */
149 /* This is only called if we terminate normally, not with an unhandled signal,
150 * so we cannot rely on it. */
152 void __attribute__((destructor
)) fini()
This page took 0.038679 seconds and 4 git commands to generate.