ibus: fall back from unreadable machine id
This commit is contained in:
@@ -24,6 +24,49 @@ struct Ibusfix
|
||||
int pumpactive;
|
||||
};
|
||||
|
||||
void
|
||||
ibus_machine_id_fallback(struct ct *t)
|
||||
{
|
||||
char root[] = "/tmp/strans-machine-id.XXXXXX";
|
||||
char primary[128], fallback[128], got[64];
|
||||
char *path[2];
|
||||
FILE *fp;
|
||||
int madeprimary, madefallback;
|
||||
|
||||
madeprimary = 0;
|
||||
madefallback = 0;
|
||||
if(!CT_CHECK(t, mkdtemp(root) != nil))
|
||||
return;
|
||||
if(!CT_CHECK(t, snprintf(primary, sizeof primary, "%s/primary", root)
|
||||
< (int)sizeof primary) ||
|
||||
!CT_CHECK(t, snprintf(fallback, sizeof fallback, "%s/fallback", root)
|
||||
< (int)sizeof fallback))
|
||||
goto cleanup;
|
||||
if(!CT_CHECK(t, mkdir(primary, 0700) == 0))
|
||||
goto cleanup;
|
||||
madeprimary = 1;
|
||||
fp = fopen(fallback, "w");
|
||||
if(!CT_CHECK(t, fp != nil))
|
||||
goto cleanup;
|
||||
madefallback = 1;
|
||||
if(!CT_CHECK(t, fputs("fallback-machine-id\n", fp) >= 0)){
|
||||
fclose(fp);
|
||||
goto cleanup;
|
||||
}
|
||||
if(!CT_CHECK(t, fclose(fp) == 0))
|
||||
goto cleanup;
|
||||
path[0] = primary;
|
||||
path[1] = fallback;
|
||||
machineidfiles(got, sizeof got, path, nelem(path));
|
||||
CT_EQ_STR(t, "fallback-machine-id", got);
|
||||
cleanup:
|
||||
if(madefallback)
|
||||
CT_CHECK(t, unlink(fallback) == 0);
|
||||
if(madeprimary)
|
||||
CT_CHECK(t, rmdir(primary) == 0);
|
||||
CT_CHECK(t, rmdir(root) == 0);
|
||||
}
|
||||
|
||||
static void
|
||||
enginepump(void *arg)
|
||||
{
|
||||
|
||||
@@ -71,5 +71,6 @@ void ipc_response_max_and_drain(struct ct*);
|
||||
void ipc_response_fragmented_and_truncated(struct ct*);
|
||||
void ipc_broken_peer_send(struct ct*);
|
||||
void server_connection_ownership(struct ct*);
|
||||
void ibus_machine_id_fallback(struct ct*);
|
||||
void ibus_context_lifecycle(struct ct*);
|
||||
void ibus_active_release_lifecycle(struct ct*);
|
||||
|
||||
@@ -125,6 +125,7 @@ static const struct ct_test tests[] = {
|
||||
{ "ipc/response-fragmented-truncated", ipc_response_fragmented_and_truncated },
|
||||
{ "ipc/broken-peer-send", ipc_broken_peer_send },
|
||||
{ "server/connection-ownership", server_connection_ownership },
|
||||
{ "ibus/machine-id-fallback", ibus_machine_id_fallback },
|
||||
{ "ibus/context-lifecycle", ibus_context_lifecycle },
|
||||
{ "ibus/active-release-lifecycle", ibus_active_release_lifecycle },
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user