Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #59 from monich/ioerr
Gracefully fail on error to create temporary file or directory
  • Loading branch information
monich committed Dec 12, 2014
2 parents 1159f08 + 265fe4b commit f043017
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
28 changes: 15 additions & 13 deletions mms-lib/src/mms_task_decode.c
Expand Up @@ -301,20 +301,22 @@ mms_task_decode_new(
const char* transaction_id,
const char* file)
{
MMSTaskDecode* dec = mms_task_alloc(MMS_TYPE_TASK_DECODE,
parent->settings, parent->handler, "Decode", parent->id,
parent->imsi);
GError* error = NULL;
dec->map = g_mapped_file_new(file, FALSE, &error);
if (dec->map) {
dec->transaction_id = g_strdup(transaction_id);
dec->file = g_strdup(file);
return &dec->task;
} else {
MMS_ERR("%s", MMS_ERRMSG(error));
g_error_free(error);
return NULL;
if (file) {
MMSTaskDecode* dec = mms_task_alloc(MMS_TYPE_TASK_DECODE,
parent->settings, parent->handler, "Decode", parent->id,
parent->imsi);
GError* error = NULL;
dec->map = g_mapped_file_new(file, FALSE, &error);
if (dec->map) {
dec->transaction_id = g_strdup(transaction_id);
dec->file = g_strdup(file);
return &dec->task;
} else if (error) {
MMS_ERR("%s", MMS_ERRMSG(error));
g_error_free(error);
}
}
return NULL;
}

/*
Expand Down
21 changes: 14 additions & 7 deletions mms-lib/src/mms_task_http.c
Expand Up @@ -413,7 +413,8 @@ mms_task_http_start(
}

if ((!priv->send_path || send_fd >= 0) &&
(!priv->receive_path || receive_fd >= 0)) {
(!priv->receive_path || receive_fd >= 0) &&
(send_fd >= 0 || receive_fd >= 0)) {

/* Set up the transfer */
const char* uri = priv->uri ? priv->uri : connection->mmsc;
Expand Down Expand Up @@ -476,10 +477,9 @@ mms_task_http_start(

return TRUE;
}
} else {
if (receive_fd >= 0) close(receive_fd);
if (send_fd >= 0) close(send_fd);
}
if (receive_fd >= 0) close(receive_fd);
if (send_fd >= 0) close(send_fd);
return FALSE;
}

Expand All @@ -490,9 +490,16 @@ mms_task_http_transmit(
MMSConnection* conn)
{
if (task->state != MMS_TASK_STATE_TRANSMITTING) {
mms_task_set_state(task,
mms_task_http_start(MMS_TASK_HTTP(task), conn) ?
MMS_TASK_STATE_TRANSMITTING : MMS_TASK_STATE_DONE);
MMSTaskHttp* http = MMS_TASK_HTTP(task);
if (mms_task_http_start(http, conn)) {
mms_task_set_state(task, MMS_TASK_STATE_TRANSMITTING);
} else {
MMSTaskHttpClass* klass = MMS_TASK_HTTP_GET_CLASS(task);
if (klass->fn_done) {
klass->fn_done(http, NULL, SOUP_STATUS_IO_ERROR);
}
mms_task_set_state(task, MMS_TASK_STATE_DONE);
}
}
}

Expand Down

0 comments on commit f043017

Please sign in to comment.