Just change var and func names to short
This commit is contained in:
parent
610cbdf962
commit
31a16dbb14
124
wyebrun.c
124
wyebrun.c
|
@ -116,7 +116,7 @@ static bool ipcsend(char *exe, char *name,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean ipccb(GIOChannel *ch, GIOCondition c, gpointer p);
|
static gboolean ipccb(GIOChannel *ch, GIOCondition cnd, gpointer p);
|
||||||
|
|
||||||
static GSource *ipcwatch(char *exe, char *name, GMainContext *ctx, gpointer p)
|
static GSource *ipcwatch(char *exe, char *name, GMainContext *ctx, gpointer p)
|
||||||
{
|
{
|
||||||
|
@ -280,55 +280,55 @@ static void __attribute__((destructor)) removepp()
|
||||||
for (; rmpath; rmpath = rmpath->next)
|
for (; rmpath; rmpath = rmpath->next)
|
||||||
remove(rmpath->data);
|
remove(rmpath->data);
|
||||||
}
|
}
|
||||||
static Client *makecli()
|
static Client *makecl()
|
||||||
{
|
{
|
||||||
Client *cli = g_new0(Client, 1);
|
Client *c = g_new0(Client, 1);
|
||||||
g_mutex_init(&cli->retm);
|
g_mutex_init(&c->retm);
|
||||||
static int tid = 0;
|
static int tid = 0;
|
||||||
cli->pid = g_strdup_printf("%d-%u", tid++, getpid());
|
c->pid = g_strdup_printf("%d-%u", tid++, getpid());
|
||||||
|
|
||||||
cli->wctx = g_main_context_new();
|
c->wctx = g_main_context_new();
|
||||||
cli->loop = g_main_loop_new(cli->wctx, true);
|
c->loop = g_main_loop_new(c->wctx, true);
|
||||||
cli->watch = ipcwatch(CLIDIR, cli->pid, cli->wctx, cli);
|
c->watch = ipcwatch(CLIDIR, c->pid, c->wctx, c);
|
||||||
cli->pppath = ipcpath( CLIDIR, cli->pid);
|
c->pppath = ipcpath( CLIDIR, c->pid);
|
||||||
g_mutex_lock(&rmm);
|
g_mutex_lock(&rmm);
|
||||||
rmpath = g_slist_prepend(rmpath, cli->pppath);
|
rmpath = g_slist_prepend(rmpath, c->pppath);
|
||||||
g_mutex_unlock(&rmm);
|
g_mutex_unlock(&rmm);
|
||||||
|
|
||||||
g_thread_unref(g_thread_new("wait", (GThreadFunc)g_main_loop_run, cli->loop));
|
g_thread_unref(g_thread_new("wait", (GThreadFunc)g_main_loop_run, c->loop));
|
||||||
|
|
||||||
return cli;
|
return c;
|
||||||
}
|
}
|
||||||
static void freecli(Client *cli)
|
static void freecl(Client *c)
|
||||||
{
|
{
|
||||||
g_main_loop_quit(cli->loop);
|
g_main_loop_quit(c->loop);
|
||||||
g_source_unref(cli->watch);
|
g_source_unref(c->watch);
|
||||||
g_main_loop_unref(cli->loop);
|
g_main_loop_unref(c->loop);
|
||||||
g_main_context_unref(cli->wctx);
|
g_main_context_unref(c->wctx);
|
||||||
g_mutex_clear(&cli->retm);
|
g_mutex_clear(&c->retm);
|
||||||
g_free(cli->pid);
|
g_free(c->pid);
|
||||||
g_free(cli->retdata);
|
g_free(c->retdata);
|
||||||
remove(cli->pppath);
|
remove(c->pppath);
|
||||||
g_mutex_lock(&rmm);
|
g_mutex_lock(&rmm);
|
||||||
rmpath = g_slist_remove(rmpath, cli->pppath);
|
rmpath = g_slist_remove(rmpath, c->pppath);
|
||||||
g_mutex_unlock(&rmm);
|
g_mutex_unlock(&rmm);
|
||||||
g_free(cli->pppath);
|
g_free(c->pppath);
|
||||||
}
|
}
|
||||||
static Client *getcli()
|
static Client *getcl()
|
||||||
{
|
{
|
||||||
static GMutex m;
|
static GMutex m;
|
||||||
g_mutex_lock(&m);
|
g_mutex_lock(&m);
|
||||||
|
|
||||||
static GPrivate pc = G_PRIVATE_INIT((GDestroyNotify)freecli);
|
static GPrivate pc = G_PRIVATE_INIT((GDestroyNotify)freecl);
|
||||||
Client *cli = g_private_get(&pc);
|
Client *c = g_private_get(&pc);
|
||||||
|
|
||||||
if (!cli)
|
if (!c)
|
||||||
{
|
{
|
||||||
cli = makecli();
|
c = makecl();
|
||||||
g_private_set(&pc, cli);
|
g_private_set(&pc, c);
|
||||||
}
|
}
|
||||||
g_mutex_unlock(&m);
|
g_mutex_unlock(&m);
|
||||||
return cli;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GHashTable *lastsec = NULL;
|
static GHashTable *lastsec = NULL;
|
||||||
|
@ -351,32 +351,32 @@ static char *keepstr(char *exe)
|
||||||
#undef Z
|
#undef Z
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean pingloop(Client *cli)
|
static gboolean pingloop(Client *c)
|
||||||
{
|
{
|
||||||
if (!ipcsend(cli->exe, PING, CSping, cli->pid, keepstr(cli->exe)))
|
if (!ipcsend(c->exe, PING, CSping, c->pid, keepstr(c->exe)))
|
||||||
g_mutex_unlock(&cli->retm);
|
g_mutex_unlock(&c->retm);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static gboolean timeoutcb(Client *cli)
|
static gboolean timeoutcb(Client *c)
|
||||||
{
|
{
|
||||||
g_mutex_unlock(&cli->retm);
|
g_mutex_unlock(&c->retm);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//don't free
|
//don't free
|
||||||
static char *request(char *exe, Com type, bool caller, char *data)
|
static char *request(char *exe, Com type, bool caller, char *data)
|
||||||
{
|
{
|
||||||
Client *cli = getcli();
|
Client *c = getcl();
|
||||||
|
|
||||||
if (caller)
|
if (caller)
|
||||||
{
|
{
|
||||||
g_mutex_lock(&cli->retm);
|
g_mutex_lock(&c->retm);
|
||||||
g_free(cli->retdata);
|
g_free(c->retdata);
|
||||||
cli->retdata = NULL;
|
c->retdata = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ipcsend(exe, INPUT, type, caller ? cli->pid : NULL, data))
|
if (!ipcsend(exe, INPUT, type, caller ? c->pid : NULL, data))
|
||||||
{ //svr is not running
|
{ //svr is not running
|
||||||
char *path = ipcpath(exe, "lock");
|
char *path = ipcpath(exe, "lock");
|
||||||
if (!g_file_test(path, G_FILE_TEST_EXISTS))
|
if (!g_file_test(path, G_FILE_TEST_EXISTS))
|
||||||
|
@ -387,20 +387,20 @@ static char *request(char *exe, Com type, bool caller, char *data)
|
||||||
flock(lock, LOCK_EX);
|
flock(lock, LOCK_EX);
|
||||||
|
|
||||||
//retry in single proc
|
//retry in single proc
|
||||||
if (!ipcsend(exe, INPUT, type, caller ? cli->pid : NULL, data))
|
if (!ipcsend(exe, INPUT, type, caller ? c->pid : NULL, data))
|
||||||
{
|
{
|
||||||
if (!caller)
|
if (!caller)
|
||||||
g_mutex_lock(&cli->retm);
|
g_mutex_lock(&c->retm);
|
||||||
|
|
||||||
GSource *tout = g_timeout_source_new(KEEPS * 1000);
|
GSource *tout = g_timeout_source_new(KEEPS * 1000);
|
||||||
g_source_set_callback(tout, (GSourceFunc)timeoutcb, cli, NULL);
|
g_source_set_callback(tout, (GSourceFunc)timeoutcb, c, NULL);
|
||||||
g_source_attach(tout, cli->wctx);
|
g_source_attach(tout, c->wctx);
|
||||||
|
|
||||||
|
|
||||||
char **argv = g_new0(char*, 4);
|
char **argv = g_new0(char*, 4);
|
||||||
argv[0] = exe;
|
argv[0] = exe;
|
||||||
argv[1] = PREFIX;
|
argv[1] = PREFIX;
|
||||||
argv[2] = cli->pid;
|
argv[2] = c->pid;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
|
if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
|
||||||
NULL, NULL, NULL, &err))
|
NULL, NULL, NULL, &err))
|
||||||
|
@ -411,8 +411,8 @@ static char *request(char *exe, Com type, bool caller, char *data)
|
||||||
g_free(argv);
|
g_free(argv);
|
||||||
|
|
||||||
|
|
||||||
g_mutex_lock(&cli->retm);
|
g_mutex_lock(&c->retm);
|
||||||
g_mutex_unlock(&cli->retm);
|
g_mutex_unlock(&c->retm);
|
||||||
|
|
||||||
g_source_destroy(tout);
|
g_source_destroy(tout);
|
||||||
g_source_unref(tout);
|
g_source_unref(tout);
|
||||||
|
@ -421,8 +421,8 @@ static char *request(char *exe, Com type, bool caller, char *data)
|
||||||
wyebkeep(exe, 0);
|
wyebkeep(exe, 0);
|
||||||
|
|
||||||
if (caller)
|
if (caller)
|
||||||
g_mutex_lock(&cli->retm);
|
g_mutex_lock(&c->retm);
|
||||||
if (!ipcsend(exe, INPUT, type, caller ? cli->pid : NULL, data))
|
if (!ipcsend(exe, INPUT, type, caller ? c->pid : NULL, data))
|
||||||
P(Spawning %s failed !!, exe)
|
P(Spawning %s failed !!, exe)
|
||||||
}
|
}
|
||||||
close(lock);
|
close(lock);
|
||||||
|
@ -431,18 +431,18 @@ static char *request(char *exe, Com type, bool caller, char *data)
|
||||||
if (caller)
|
if (caller)
|
||||||
{
|
{
|
||||||
GSource *ping = g_timeout_source_new(DPINGTIME);
|
GSource *ping = g_timeout_source_new(DPINGTIME);
|
||||||
cli->exe = exe;
|
c->exe = exe;
|
||||||
g_source_set_callback(ping, (GSourceFunc)pingloop, cli, NULL);
|
g_source_set_callback(ping, (GSourceFunc)pingloop, c, NULL);
|
||||||
g_source_attach(ping, cli->wctx); //attach to ping thread
|
g_source_attach(ping, c->wctx); //attach to ping thread
|
||||||
|
|
||||||
g_mutex_lock(&cli->retm);
|
g_mutex_lock(&c->retm);
|
||||||
g_mutex_unlock(&cli->retm);
|
g_mutex_unlock(&c->retm);
|
||||||
|
|
||||||
g_source_destroy(ping);
|
g_source_destroy(ping);
|
||||||
g_source_unref(ping);
|
g_source_unref(ping);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cli->retdata;
|
return c->retdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *wyebget(char *exe, char *data)
|
char *wyebget(char *exe, char *data)
|
||||||
|
@ -487,10 +487,10 @@ static void testget(gpointer p, gpointer ap)
|
||||||
g_free(p);
|
g_free(p);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
static gboolean tcinputcb(GIOChannel *ch, GIOCondition c, char *exe)
|
static gboolean tcinputcb(GIOChannel *ch, GIOCondition cnd, char *exe)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
if (c == G_IO_HUP || G_IO_STATUS_EOF ==
|
if (cnd == G_IO_HUP || G_IO_STATUS_EOF ==
|
||||||
g_io_channel_read_line(ch, &line, NULL, NULL, NULL))
|
g_io_channel_read_line(ch, &line, NULL, NULL, NULL))
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
@ -566,7 +566,7 @@ void wyebclient(char *exe)
|
||||||
|
|
||||||
|
|
||||||
//@ipccb
|
//@ipccb
|
||||||
gboolean ipccb(GIOChannel *ch, GIOCondition c, gpointer p)
|
gboolean ipccb(GIOChannel *ch, GIOCondition cnd, gpointer p)
|
||||||
{
|
{
|
||||||
//D(ipccb %c, svrexe ? 'S':'C')
|
//D(ipccb %c, svrexe ? 'S':'C')
|
||||||
char *line;
|
char *line;
|
||||||
|
@ -611,13 +611,13 @@ gboolean ipccb(GIOChannel *ch, GIOCondition c, gpointer p)
|
||||||
case CClost:
|
case CClost:
|
||||||
case CCwoke:
|
case CCwoke:
|
||||||
{
|
{
|
||||||
Client *cli = p;
|
Client *c = p;
|
||||||
if (type == CCret)
|
if (type == CCret)
|
||||||
cli->retdata = g_strcompress(data);
|
c->retdata = g_strcompress(data);
|
||||||
|
|
||||||
//for the case pinging at same time of ret
|
//for the case pinging at same time of ret
|
||||||
g_mutex_trylock(&cli->retm);
|
g_mutex_trylock(&c->retm);
|
||||||
g_mutex_unlock(&cli->retm);
|
g_mutex_unlock(&c->retm);
|
||||||
g_thread_yield();
|
g_thread_yield();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user