aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-clipboard.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-12-09 13:15:10 +0100
committerMattias Andrée <maandree@operamail.com>2014-12-09 13:15:10 +0100
commit7a994c9631c590d6a73c842fa5d2d3567b4771dd (patch)
tree228ade01f99ba217151a0ed20f29c5f3a5028619 /src/mds-clipboard.c
parentmds-kbdc: compile-layout: macro_call: fix bug: do not duplicate the arguments if there are none (diff)
parentreport an error, rather than causing failure the caller but not for the called function (diff)
downloadmds-7a994c9631c590d6a73c842fa5d2d3567b4771dd.tar.gz
mds-7a994c9631c590d6a73c842fa5d2d3567b4771dd.tar.bz2
mds-7a994c9631c590d6a73c842fa5d2d3567b4771dd.tar.xz
merge track-errors and resolve conflict
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/mds-clipboard.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/mds-clipboard.c b/src/mds-clipboard.c
index 1d4de37..50ee6a3 100644
--- a/src/mds-clipboard.c
+++ b/src/mds-clipboard.c
@@ -105,6 +105,7 @@ int __attribute__((const)) preinitialise_server(void)
int initialise_server(void)
{
ssize_t i = 0;
+ int stage = 0;
const char* const message =
"Command: intercept\n"
"Message ID: 0\n"
@@ -113,8 +114,7 @@ int initialise_server(void)
"Command: clipboard\n"
"Client closed\n";
- if (full_send(message, strlen(message)))
- return 1;
+ fail_if (full_send(message, strlen(message)));
if (is_respawn)
{
@@ -124,13 +124,13 @@ int initialise_server(void)
"Message ID: 1\n"
"\n";
- if (full_send(crash_message, strlen(crash_message)))
- return 1;
-
+ fail_if (full_send(crash_message, strlen(crash_message)));
message_id++;
}
+ stage++;
fail_if (server_initialised() < 0);
+ stage++;
fail_if (mds_message_initialise(&received));
for (i = 0; i < CLIPBOARD_LEVELS; i++)
@@ -138,10 +138,12 @@ int initialise_server(void)
return 0;
- pfail:
+ fail:
xperror(*argv);
+ if (stage == 0) return 1;
mds_message_destroy(&received);
- while (--i >= 0)
+ if (stage == 1) return 1;
+ while (i--)
free(clipboard[i]);
return 1;
}
@@ -158,13 +160,12 @@ int postinitialise_server(void)
if (connected)
return 0;
- if (reconnect_to_display())
- {
- mds_message_destroy(&received);
- return 1;
- }
+ fail_if (reconnect_to_display());
connected = 1;
return 0;
+ fail:
+ mds_message_destroy(&received);
+ return 1;
}
@@ -305,7 +306,7 @@ int unmarshal_server(char* state_buf)
}
return 0;
- pfail:
+ fail:
xperror(*argv);
mds_message_destroy(&received);
for (i = 0; i < CLIPBOARD_LEVELS; i++)
@@ -357,27 +358,26 @@ int master_loop(void)
if (r == -2)
{
eprint("corrupt message received, aborting.");
- goto fail;
+ goto done;
}
else if (errno == EINTR)
continue;
- else if (errno != ECONNRESET)
- goto pfail;
+ else
+ fail_if (errno != ECONNRESET);
eprint("lost connection to server.");
mds_message_destroy(&received);
mds_message_initialise(&received);
connected = 0;
- if (reconnect_to_display())
- goto fail;
+ fail_if (reconnect_to_display());
connected = 1;
}
rc = 0;
- goto fail;
- pfail:
- xperror(*argv);
+ goto done;
fail:
+ xperror(*argv);
+ done:
if (!rc && reexecing)
return 0;
mds_message_destroy(&received);
@@ -411,15 +411,15 @@ int full_send(const char* message, size_t length)
eprint("Sent more of a message than exists in the message, aborting.");
return -1;
}
- else if ((sent < length) && (errno != EINTR))
- {
- xperror(*argv);
- return -1;
- }
+ else
+ fail_if ((sent < length) && (errno != EINTR));
message += sent;
length -= sent;
}
return 0;
+ fail:
+ xperror(*argv);
+ return -1;
}
@@ -576,8 +576,7 @@ static int clipboard_notify_pop(int level, size_t index)
"Used: %zu\n"
"\n");
- if (xmalloc(message, n, char))
- return -1;
+ fail_if (xmalloc(message, n, char));
sprintf(message,
"Command: clipboard-info\n"
@@ -592,6 +591,8 @@ static int clipboard_notify_pop(int level, size_t index)
message_id = message_id == UINT32_MAX ? 0 : (message_id + 1);
return full_send(message, strlen(message)) ? -1 : 0;
+ fail:
+ return -1;
}
@@ -637,7 +638,7 @@ static int clipboard_purge(int level, const char* client_id)
}
return 0;
- pfail:
+ fail:
xperror(*argv);
return -1;
}
@@ -652,9 +653,10 @@ int clipboard_danger(void)
{
int i;
for (i = 0; i < CLIPBOARD_LEVELS; i++)
- if (clipboard_purge(i, NULL))
- return -1;
+ fail_if (clipboard_purge(i, NULL));
return 0;
+ fail:
+ return -1;
}
@@ -668,9 +670,10 @@ int clipboard_death(const char* recv_client_id)
{
int i;
for (i = 0; i < CLIPBOARD_LEVELS; i++)
- if (clipboard_purge(i, recv_client_id))
- return -1;
+ fail_if (clipboard_purge(i, recv_client_id));
return 0;
+ fail:
+ return -1;
}
@@ -688,8 +691,7 @@ int clipboard_add(int level, const char* time_to_live, const char* recv_client_i
uint64_t client = recv_client_id ? parse_client_id(recv_client_id) : 0;
clipitem_t new_clip;
- if (clipboard_purge(level, NULL))
- return -1;
+ fail_if (clipboard_purge(level, NULL));
if (strequals(time_to_live, "forever"))
autopurge = CLIPITEM_AUTOPURGE_NEVER;
@@ -728,7 +730,7 @@ int clipboard_add(int level, const char* time_to_live, const char* recv_client_i
clipboard[level][0] = new_clip;
return 0;
- pfail:
+ fail:
xperror(*argv);
return -1;
}
@@ -749,8 +751,7 @@ int clipboard_read(int level, size_t index, const char* recv_client_id, const ch
clipitem_t* clip = NULL;
size_t n;
- if (clipboard_purge(level, NULL))
- return -1;
+ fail_if (clipboard_purge(level, NULL));
if (clipboard_used[level] == 0)
{
@@ -802,7 +803,7 @@ int clipboard_read(int level, size_t index, const char* recv_client_id, const ch
free(message);
return 0;
- pfail:
+ fail:
xperror(*argv);
return -1;
}
@@ -834,8 +835,7 @@ int clipboard_clear(int level)
int clipboard_set_size(int level, size_t size)
{
size_t i;
- if (clipboard_purge(level, NULL))
- return -1;
+ fail_if (clipboard_purge(level, NULL));
if (size < clipboard_size[level])
{
@@ -854,13 +854,13 @@ int clipboard_set_size(int level, size_t size)
if (xrealloc(clipboard[level], size, clipitem_t))
{
clipboard[level] = old;
- goto pfail;
+ fail_if (1);
}
clipboard_size[level] = size;
}
return 0;
- pfail:
+ fail:
xperror(*argv);
return -1;
}
@@ -878,8 +878,8 @@ int clipboard_get_size(int level, const char* recv_client_id, const char* recv_m
{
char* message = NULL;
size_t n;
- if (clipboard_purge(level, NULL))
- return -1;
+
+ fail_if (clipboard_purge(level, NULL));
n = strlen("To: %s\n"
"In response to: %s\n"
@@ -905,7 +905,7 @@ int clipboard_get_size(int level, const char* recv_client_id, const char* recv_m
free(message);
return 0;
- pfail:
+ fail:
xperror(*argv);
free(message);
return -1;