Skip to content

Commit

Permalink
Clean out unused error codes and set actual proper messages
Browse files Browse the repository at this point in the history
This patch, inspired by anyuta1166#5, not only cleans out unused
error codes, but adds human-readable error descriptions as well.

Inadyn has for a long time now had better syslog messages in general,
and with this we now also get a better dying gasp message on failure.

Signed-off-by: Joachim Nilsson <[email protected]>
  • Loading branch information
troglobit committed Jun 27, 2017
1 parent 30992be commit 7e62411
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 67 deletions.
22 changes: 7 additions & 15 deletions include/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,31 @@
#define RC_ERROR 1
#define RC_INVALID_POINTER 2
#define RC_OUT_OF_MEMORY 3
#define RC_OUT_BUFFER_OVERFLOW 4
#define RC_HTTPS_NO_TRUSTED_CA_STORE 5
#define RC_PIDFILE_EXISTS_ALREADY 6
#define RC_BUFFER_OVERFLOW 4
#define RC_PIDFILE_EXISTS_ALREADY 5

#define RC_IP_SOCKET_CREATE_ERROR 10
#define RC_IP_BAD_PARAMETER 11
#define RC_IP_INVALID_REMOTE_ADDR 12
#define RC_IP_CONNECT_FAILED 13
#define RC_IP_SEND_ERROR 14
#define RC_IP_RECV_ERROR 15
#define RC_IP_OBJECT_NOT_INITIALIZED 16
#define RC_IP_OS_SOCKET_INIT_FAILED 17

#define RC_TCP_OBJECT_NOT_INITIALIZED 20
#define RC_IP_OBJECT_NOT_INITIALIZED 20
#define RC_TCP_OBJECT_NOT_INITIALIZED 21
#define RC_HTTP_OBJECT_NOT_INITIALIZED 22

#define RC_HTTP_OBJECT_NOT_INITIALIZED 30
#define RC_HTTP_BAD_PARAMETER 31
#define RC_HTTPS_NO_TRUSTED_CA_STORE 31
#define RC_HTTPS_OUT_OF_MEMORY 32
#define RC_HTTPS_FAILED_CONNECT 33
#define RC_HTTPS_FAILED_GETTING_CERT 34
#define RC_HTTPS_NO_SSL_SUPPORT 35
#define RC_HTTPS_SEND_ERROR 36
#define RC_HTTPS_RECV_ERROR 37
#define RC_HTTPS_SNI_ERROR 38
#define RC_HTTPS_INVALID_REQUEST 39

#define RC_DDNS_BUFFER_TOO_SMALL 40
#define RC_DDNS_INVALID_CHECKIP_RSP 42
#define RC_DDNS_INVALID_OPTION 44
#define RC_DDNS_INVAL_MISSING_PARAM 45
#define RC_DDNS_INVALID_OPTION 45
#define RC_DDNS_RSP_NOTOK 48
#define RC_DDNS_RSP_RETRY_LATER 49

Expand All @@ -67,9 +62,6 @@
#define RC_OS_INVALID_GID 65
#define RC_OS_INSTALL_SIGHANDLER_FAILED 66

#define RC_FILE_IO_OPEN_ERROR 70
#define RC_FILE_IO_READ_ERROR 71
#define RC_FILE_IO_OUT_OF_BUFFER 72
#define RC_FILE_IO_ACCESS_ERROR 73
#define RC_FILE_IO_MISSING_FILE 74

Expand Down
8 changes: 4 additions & 4 deletions plugins/cloudxns.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)
*/
tmp = strchr(trans.rsp_body, '[');
if (!tmp) {
rc = RC_DDNS_INVAL_MISSING_PARAM;
rc = RC_DDNS_INVALID_OPTION;
break;
}

Expand All @@ -179,7 +179,7 @@ static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)

if (domain_id == 0) {
logit(LOG_ERR, "Hostname '%s' not found in domains list!", alias->name);
rc = RC_DDNS_INVAL_MISSING_PARAM;
rc = RC_DDNS_INVALID_OPTION;
break;
}
logit(LOG_DEBUG, "CloudXNS Domain: '%s' ID: %u", domain, domain_id);
Expand Down Expand Up @@ -220,7 +220,7 @@ static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)

tmp = strchr(trans.rsp_body, '[');
if (!tmp) {
rc = RC_DDNS_INVAL_MISSING_PARAM;
rc = RC_DDNS_INVALID_OPTION;
break;
}

Expand Down Expand Up @@ -250,7 +250,7 @@ static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)

if (record_id == 0) {
logit(LOG_ERR, "Record '%s' not found in records list!", prefix);
rc = RC_DDNS_INVAL_MISSING_PARAM;
rc = RC_DDNS_INVALID_OPTION;
break;
}
logit(LOG_DEBUG, "CloudXNS Record: '%s' ID: %u", prefix, record_id);
Expand Down
2 changes: 1 addition & 1 deletion plugins/zerigo.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static int response(http_trans_t *trans, ddns_info_t *UNUSED(info), ddns_alias_t
return 0;

case 4:
return RC_DDNS_INVAL_MISSING_PARAM;
return RC_DDNS_INVALID_OPTION;

case 5:
return RC_DDNS_RSP_RETRY_LATER;
Expand Down
2 changes: 1 addition & 1 deletion src/ddns.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ static int get_encoded_user_passwd(void)
if (rc2) {
logit(LOG_WARNING, "Failed base64 encoding user:pass for %s!", info->system->name);
free(encode);
rc = RC_OUT_BUFFER_OVERFLOW;
rc = RC_BUFFER_OVERFLOW;
break;
}

Expand Down
85 changes: 39 additions & 46 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,45 @@ typedef struct {
} ERROR_NAME;

static const ERROR_NAME global_error_table[] = {
{ RC_OK, "RC_OK" },
{ RC_ERROR, "RC_ERROR" },
{ RC_INVALID_POINTER, "RC_INVALID_POINTER" },
{ RC_OUT_OF_MEMORY, "RC_OUT_OF_MEMORY" },
{ RC_OUT_BUFFER_OVERFLOW, "RC_OUT_BUFFER_OVERFLOW" },
{ RC_PIDFILE_EXISTS_ALREADY, "RC_PIDFILE_EXISTS_ALREADY" },

{ RC_IP_SOCKET_CREATE_ERROR, "RC_IP_SOCKET_CREATE_ERROR" },
{ RC_IP_BAD_PARAMETER, "RC_IP_BAD_PARAMETER" },
{ RC_IP_INVALID_REMOTE_ADDR, "RC_IP_INVALID_REMOTE_ADDR" },
{ RC_IP_CONNECT_FAILED, "RC_IP_CONNECT_FAILED" },
{ RC_IP_SEND_ERROR, "RC_IP_SEND_ERROR" },
{ RC_IP_RECV_ERROR, "RC_IP_RECV_ERROR" },
{ RC_IP_OBJECT_NOT_INITIALIZED, "RC_IP_OBJECT_NOT_INITIALIZED" },
{ RC_IP_OS_SOCKET_INIT_FAILED, "RC_IP_OS_SOCKET_INIT_FAILED" },

{ RC_TCP_OBJECT_NOT_INITIALIZED, "RC_TCP_OBJECT_NOT_INITIALIZED" },

{ RC_HTTP_OBJECT_NOT_INITIALIZED, "RC_HTTP_OBJECT_NOT_INITIALIZED" },
{ RC_HTTP_BAD_PARAMETER, "RC_HTTP_BAD_PARAMETER" },

{ RC_HTTPS_NO_TRUSTED_CA_STORE, "RC_HTTPS_NO_TRUSTED_CA_STORE" },
{ RC_HTTPS_OUT_OF_MEMORY, "RC_HTTPS_OUT_OF_MEMORY" },
{ RC_HTTPS_FAILED_CONNECT, "RC_HTTPS_FAILED_CONNECT" },
{ RC_HTTPS_FAILED_GETTING_CERT, "RC_HTTPS_FAILED_GETTING_CERT" },
{ RC_HTTPS_NO_SSL_SUPPORT, "RC_HTTPS_NO_SSL_SUPPORT" },
{ RC_HTTPS_SEND_ERROR, "RC_HTTPS_SEND_ERROR" },
{ RC_HTTPS_RECV_ERROR, "RC_HTTPS_RECV_ERROR" },
{ RC_HTTPS_SNI_ERROR, "RC_HTTPS_SNI_ERROR" },
{ RC_HTTPS_INVALID_REQUEST, "RC_HTTPS_INVALID_REQUEST" },

{ RC_DDNS_BUFFER_TOO_SMALL, "RC_DDNS_BUFFER_TOO_SMALL" },
{ RC_DDNS_INVALID_CHECKIP_RSP, "RC_DDNS_INVALID_CHECKIP_RSP" },
{ RC_DDNS_INVALID_OPTION, "RC_DDNS_INVALID_OPTION" },
{ RC_DDNS_INVAL_MISSING_PARAM, "RC_DDNS_INVAL_MISSING_PARAM" },
{ RC_DDNS_RSP_NOTOK, "RC_DDNS_RSP_NOTOK" },
{ RC_DDNS_RSP_RETRY_LATER, "RC_DDNS_RSP_RETRY_LATER" },

{ RC_OS_FORK_FAILURE, "RC_FORK_FAILURE" },
{ RC_OS_CHANGE_PERSONA_FAILURE, "RC_OS_CHANGE_PERSONA_FAILURE" },
{ RC_OS_INVALID_UID, "RC_OS_INVALID_UID" },
{ RC_OS_INVALID_GID, "RC_OS_INVALID_GID" },

{ RC_FILE_IO_OPEN_ERROR, "RC_FILE_IO_OPEN_ERROR" },
{ RC_FILE_IO_READ_ERROR, "RC_FILE_IO_READ_ERROR" },
{ RC_FILE_IO_OUT_OF_BUFFER, "RC_FILE_IO_OUT_OF_BUFFER" },
{ RC_OK, "OK" },
{ RC_ERROR, "Error" },
{ RC_INVALID_POINTER, "Invalid pointer" },
{ RC_OUT_OF_MEMORY, "Out of memory" },
{ RC_BUFFER_OVERFLOW, "Too small internal buffer" },
{ RC_PIDFILE_EXISTS_ALREADY, "Already running" },

{ RC_IP_SOCKET_CREATE_ERROR, "Failed creating IP socket" },
{ RC_IP_BAD_PARAMETER, "Invalid Internet port" },
{ RC_IP_INVALID_REMOTE_ADDR, "Temporary network error (DNS)" },
{ RC_IP_CONNECT_FAILED, "Failed connecting to DDNS server" },
{ RC_IP_SEND_ERROR, "Temporary network error (send)" },
{ RC_IP_RECV_ERROR, "Temporary network error (recv)" },

{ RC_IP_OBJECT_NOT_INITIALIZED, "Internal error (IP)" },
{ RC_TCP_OBJECT_NOT_INITIALIZED, "Internal error (TCP)" },
{ RC_HTTP_OBJECT_NOT_INITIALIZED, "Internal error (HTTP)" },

{ RC_HTTPS_NO_TRUSTED_CA_STORE, "System has no trusted CA store" },
{ RC_HTTPS_OUT_OF_MEMORY, "Out of memory (HTTPS)" },
{ RC_HTTPS_FAILED_CONNECT, "Failed connecting to DDNS server (HTTPS)" },
{ RC_HTTPS_FAILED_GETTING_CERT, "Failed retrieving DDNS server cert (HTTPS)" },
{ RC_HTTPS_SEND_ERROR, "Temporary network error (HTTPS send)" },
{ RC_HTTPS_RECV_ERROR, "Temporary network error (HTTPS recv)" },
{ RC_HTTPS_SNI_ERROR, "Failed setting HTTPS server name" },
{ RC_HTTPS_INVALID_REQUEST, "Invalid request (HTTPS)" },

{ RC_DDNS_INVALID_CHECKIP_RSP, "Check IP server response not OK" },
{ RC_DDNS_INVALID_OPTION, "Invalid or missing DDNS option" },
{ RC_DDNS_RSP_NOTOK, "DDNS server response not OK" },
{ RC_DDNS_RSP_RETRY_LATER, "DDNS server busy, try later" },

{ RC_OS_FORK_FAILURE, "Failed forking off child" },
{ RC_OS_CHANGE_PERSONA_FAILURE, "Failed dropping privileges" },
{ RC_OS_INVALID_UID, "Invalid or unknown UID" },
{ RC_OS_INVALID_GID, "Invalid or unknown GID" },

{ RC_FILE_IO_ACCESS_ERROR, "Failed create/modify file/dir" },
{ RC_FILE_IO_MISSING_FILE, "Missing .conf file" },

{ RC_OK, NULL }
};
Expand Down

0 comments on commit 7e62411

Please sign in to comment.