src/command_function.c \
src/log.c \
src/listener.c \
- src/sdb_map.c
+ src/sdb_map.c \
+ src/sdb_messages.c
SDB_CFLAGS := -O2 -g -Wall -Wno-unused-parameter
SDB_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
#include "auto_complete.h"
#include "file_sync_service.h"
#include "log.h"
+#include "sdb_messages.h"
static int parse_opt(int argc, char** argv);
static int parse_cmd(int argc, char** argv);
.func = no_parse
};
+static struct ac_element ac_forward_list= {
+ .keyword = "forward-list",
+ .func = no_parse
+};
+
static const AC_ELEMENT* pre_options[] = {&emulator_short, &emulator_long, &device_short, &device_long, &serial_short, &serial_long};
static const int pre_options_size = GET_ARRAY_SIZE(pre_options, AC_ELEMENT*);
static const AC_ELEMENT* commands[] = {&ac_root, &ac_swindow , &ac_gserial, &ac_gstate, &ac_kserver, &ac_sserver,
&ac_version, &ac_help, &ac_forward, &ac_uninstall, &ac_install, &ac_dlog, &ac_shell, &ac_pull, &ac_push, &ac_disconnect,
- &ac_connect, &ac_devices};
+ &ac_connect, &ac_devices, &ac_forward_list};
static const int cmds_size = GET_ARRAY_SIZE(commands, AC_ELEMENT*);
static int initialize_ac(int complete) {
int ac_stdout_fd = dup(STDOUT_FILENO);
if(ac_stdout_fd < 0) {
- fprintf(stderr, "error: exception happend while duplicating stdout '%s'\n", strerror(errno));
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_INITIALIZE_ENV_FAIL, F(ERR_GENERAL_DUPLICATE_FAIL, "stdout"));
+ LOG_ERROR(strerror(errno));
return -1;
}
int ac_stderr_fd = dup(STDOUT_FILENO);
if(ac_stderr_fd < 0) {
- fprintf(stderr, "error: exception happend while duplicating stdout '%s'\n", strerror(errno));
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_INITIALIZE_ENV_FAIL, F(ERR_GENERAL_DUPLICATE_FAIL, "stdout"));
+ LOG_ERROR(strerror(errno));
return -1;
}
if(null_fd < 0) {
sdb_close(null_fd);
- fprintf(stderr, "error: exception happend while opening /dev/null '%s'\n", strerror(errno));
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_INITIALIZE_ENV_FAIL, F(ERR_SYNC_OPEN_FAIL, "/dev/null"));
+ LOG_ERROR(strerror(errno));
return -1;
}
if(dup2(null_fd, STDOUT_FILENO) < 0){
sdb_close(null_fd);
- fprintf(stderr, "error: exception happend while duplicating /dev/null to the stdout '%s'\n", strerror(errno));
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_INITIALIZE_ENV_FAIL, F(ERR_GENERAL_DUPLICATE_FAIL, "/dev/null"));
+ LOG_ERROR(strerror(errno));
return -1;
}
if(dup2(null_fd, STDERR_FILENO) < 0){
sdb_close(null_fd);
fprintf(stderr, "error: exception happend while duplicating /dev/null to the stderr '%s'\n", strerror(errno));
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_INITIALIZE_ENV_FAIL, F(ERR_GENERAL_DUPLICATE_FAIL, "/dev/null"));
+ LOG_ERROR(strerror(errno));
return -1;
}
// get file stat
if(stat(src_full_path, &statbuf) == -1)
{
- fprintf(stderr, "error: exception occurred while getting file stat: %s\n", src_full_path);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_STAT_FAIL, src_full_path), strerror(errno));
goto finalize;
}
#include "log.h"
#include "sdb.h"
+#include "sdb_messages.h"
static const char *SDK_TOOL_PATH="/home/developer/sdk_tools";
static const char *APP_PATH_PREFIX="/opt/apps";
char flag = 0;
if (argc < 7 || argc > 15 ) {
- fprintf(stderr,"usage: sdb launch -p <pkgid> -e <executable> -m <run|debug|da|oprofile> [-P <port>] [-attach <pid>] [-t <gtest,gcov>] [<args...>]\n");
+ print_info("sdb launch -p <pkgid> -e <executable> -m <run|debug|da|oprofile> [-P <port>] [-attach <pid>] [-t <gtest,gcov>] [<args...>]");
return -1;
}
} else if (!strcmp(argv[i], "debug")) {
mode = 1;
} else if (!strcmp(argv[i], "da") || !strcmp(argv[i], "oprofile")) {
- fprintf(stderr,"The -m option for da and oprofile is supported in sdbd higher than 2.2.0\n");
+ print_error(SDB_MESSAGE_ERROR, ERR_LAUNCH_M_OPTION_SUPPORT, NULL);
return -1;
}
else {
- fprintf(stderr,"The -m option accepts arguments only run or debug options\n");
+ print_error(SDB_MESSAGE_ERROR, ERR_LAUNCH_M_OPTION_ARGUMENT, NULL);
return -1;
}
flag = 0;
}
case 'P': {
if (mode != 1) {
- fprintf(stderr,"The -P option should be used in debug mode\n");
+ print_error(SDB_MESSAGE_ERROR, ERR_LAUNCH_P_OPTION_DEBUG_MODE, NULL);
return -1;
}
port = atoi(argv[i]);
}
case 'a': {
if (mode != 1) {
- fprintf(stderr, "The -attach option should be used in debug mode\n");
+ print_error(SDB_MESSAGE_ERROR, ERR_LAUNCH_P_OPTION_DEBUG_MODE, NULL);
return -1;
}
pid = atoi(argv[i]);
if (verify_gdbserver_exist() < 0) {
return -1;
}
- if (!port) {
- fprintf(stderr,"The port number is not valid\n");
+ if (port <= 0 || port > 65535) {
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_LAUNCH_APP_FAIL, F(ERR_GENERAL_INVALID_PORT, port));
+
return -1;
}
if (pid) {
}
int devices(int argc, char ** argv) {
+
char *tmp;
char full_cmd[PATH_MAX];
}
printf("%c[2J%c[2H", 27, 27);
- printf("Samsung Development Bridge\n");
+ printf("Smart Development Bridge\n");
printf("State: %s\n", state ? state : "offline");
fflush(stdout);
}
int kill_server(int argc, char ** argv) {
int fd;
fd = _sdb_connect("host:kill");
- if(fd == -1) {
- fprintf(stderr,"* server not running *\n");
+ if(fd == -2) {
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_KILL_SERVER_FAIL, ERR_GENERAL_SERVER_NOT_RUN);
return 1;
}
return 0;
return r;
}
else {
- fprintf(stderr,COMMANDLINE_ERROR_ARG_MISSING, "server", "forkserver");
+ print_error(SDB_MESSAGE_ERROR, F(ERR_COMMAND_MISSING_ARGUMENT, "fork-server"), NULL);
return 1;
}
}
D("Install path%s\n", destination);
int tpk = get_pkgtype_file_name(srcpath);
if (tpk == -1) {
- fprintf(stderr, "error: unknown package type '%s'\n", srcpath);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_PACKAGE_TYPE_UNKNOWN, srcpath), NULL);
return 1;
}
else if(tpk == 0){
snprintf(full_cmd, sizeof full_cmd, SHELL_INSTALL_CMD, "wgt", destination);
}
+ else if(tpk == 2){
+ snprintf(full_cmd, sizeof full_cmd, SHELL_INSTALL_CMD, "rpm", destination);
+ }
D(COMMANDLINE_MSG_FULL_CMD, argv[0], full_cmd);
if(__sdb_command(full_cmd) < 0) {
return 0;
}
- fprintf(stderr, "failed to get package temporary path : %s", buf);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_PACKAGE_GET_TEMP_PATH_FAIL, buf), NULL);
sdb_close(fd);
return -1;
}
else if(!strcmp(pkg_type, "tpk")) {
result = 1;
}
+ else if(!strcmp(pkg_type, "rpm")) {
+ result = 2;
+ }
}
return result;
int rl_result = read_lines(result, buf, 100);
if(rl_result <= 0) {
- fprintf(stderr, "error: package '%s' does not exist\n", app_id);
+ print_error(SDB_MESSAGE_ERROR, ERR_PACKAGE_GET_TYPE_FAIL, F(ERR_PACKAGE_ID_NOT_EXIST, app_id));
return -1;
}
if(rl_result > 1) {
- fprintf(stderr, "error: '%s' is not unique package id\n", app_id);
+ print_error(SDB_MESSAGE_ERROR, ERR_PACKAGE_GET_TYPE_FAIL, F(ERR_PACKAGE_ID_NOT_UNIQUE, app_id));
return -1;
}
}
else {
if(strstr(buf, "error") != NULL) {
- fprintf(stderr, "%s\n", buf);
+ print_error(SDB_MESSAGE_ERROR, ERR_PACKAGE_GET_TYPE_FAIL, buf);
}
else {
- fprintf(stderr, "error: not supported package type '%s'\n", buf);
+ print_error(SDB_MESSAGE_ERROR, ERR_PACKAGE_TYPE_UNKNOWN, buf);
}
}
return result;
return -1;
}
if (read_line(result, buf, sizeof(buf)) > 0) {
- fprintf(stderr, "error: %s\n", buf);
+ print_error(SDB_MESSAGE_ERROR, buf, NULL);
sdb_close(result);
return -1;
}
#include "sdb_model.h"
#include "commandline.h"
#include "command_function.h"
+#include "sdb_messages.h"
static void print_help(LIST_NODE* optlist, LIST_NODE* cmdlist);
static void create_opt_list(LIST_NODE** opt_list);
n++;
if(buf[n] == '.') {
fprintf(stderr,"\n* disconnect *\n");
- stdin_raw_restore(INPUT_FD, tio_save);
- free(tio_save);
- exit(0);
+ stdin_raw_restore(INPUT_FD, tio_save);
+ free(tio_save);
+ exit(0);
}
}
}
if (tmp) {
serial = strdup(tmp);
} else {
- fprintf(stderr, "wrong serial number '%s'\n", serial);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_CONNECT_WRONG_SERIAL, serial), NULL);
return 1;
}
}
int maxargs = command->maxargs;
if(argc < minargs + 1) {
- fprintf(stderr, "%s command has following args: %s, and it requires at least %d arguments\n", argv[0], command->argdesc, minargs);
+ print_error(SDB_MESSAGE_ERROR, ERR_COMMAND_TOO_FEW_ARGUMENTS , NULL);
+ print_info("sdb %s %s", argv[0], command->argdesc);
if (serial != NULL) {
free(serial);
}
return 1;
}
if(argc > maxargs + 1 && maxargs > -1) {
- fprintf(stderr, "command %s require at most %d arguments\n", argv[0], maxargs);
+ print_error(SDB_MESSAGE_ERROR, ERR_COMMAND_TOO_MANY_ARGUMENTS , NULL);
+ print_info("sdb %s %s", argv[0], command->argdesc);
if (serial != NULL) {
free(serial);
}
static void print_help(LIST_NODE* optlist, LIST_NODE* cmdlist) {
- fprintf(stderr, "Smart Development Bridge version %d.%d.%d\n",
+ fprintf(stderr, "Smart Development Bridge %d.%d.%d\n",
SDB_VERSION_MAJOR, SDB_VERSION_MINOR, SDB_VERSION_PATCH);
fprintf(stderr, "\n Usage : sdb [option] <command> [parameters]\n\n");
fprintf(stderr, " options:\n");
#include "utils.h"
#include "fdevent.h"
#include "log.h"
+#include "sdb_messages.h"
#ifndef OS_WINDOWS
int max_select = 0;
#ifndef OS_WINDOWS
int ret = fcntl(fd, F_SETFL, O_NONBLOCK);
if(ret == -1)
- fprintf(stderr, "fail to set the file status flag\n");
+ LOG_ERROR("failed to install FD event '%d': %s\n", fd, "cannot set the status of FD");
if(fd >= max_select) {
max_select = fd + 1;
}
#include "strutils.h"
#include "fdevent.h"
#include "log.h"
+#include "sdb_messages.h"
static __inline__ void finalize(int srcfd, int dstfd, SYNC_INFO* sync_info);
int src_dir = srcF->is_dir(srcp, &src_stat);
if(src_dir == -1) {
- fprintf(stderr, ERR_REASON_SYNC_NOT_FILE, srcp);
+ print_error(SDB_MESSAGE_ERROR, ERR_SYNC_COPY_FAIL, F(ERR_SYNC_NOT_FILE, srcp));
goto error;
}
}
if(dst_dir == -1) {
- fprintf(stderr, ERR_REASON_SYNC_NOT_FILE, dstp);
+ print_error(SDB_MESSAGE_ERROR, ERR_SYNC_COPY_FAIL, F(ERR_SYNC_NOT_FILE, dstp));
goto error;
}
while(dir_list != NULL) {
LIST_NODE* entry_list = NULL;
COPY_INFO* _info = (COPY_INFO*)dir_list->data;
+
if(srcF->get_dirlist(src_fd, _info->src, _info->dst, &entry_list, sync_info)) {
fprintf(stderr,"skipped: %s -> %s\n", _info->src, _info->dst);
sync_info->skipped++;
src_dir = srcF->is_dir(src_p, &(copy_info->_stat));
if(src_dir < 0) {
- fprintf(stderr,ERR_REASON_SYNC_NOT_FILE, src_p);
+ print_error(SDB_MESSAGE_ERROR, ERR_SYNC_COPY_FAIL, F(ERR_SYNC_NOT_FILE, src_p));
goto skip_in;
}
if(src_dir == 1) {
append(&dir_list, copy_info);
+ D("copy destination info = %s\n", copy_info->dst);
continue;
}
else {
#include "strutils.h"
#include "file_sync_client.h"
#include "log.h"
+#include "sdb_messages.h"
const unsigned sync_stat = MKSYNC('S','T','A','T');
const unsigned sync_list = MKSYNC('L','I','S','T');
int fd = sdb_connect("sync:");
if(fd < 0) {
- print_error(1, ERR_SITU_SYNC_OPEN_CHANNEL, ERR_REASON_GENERAL_CONNECTION_FAIL, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, ERR_SYNC_OPEN_CHANNEL_FAIL, ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
return fd;
D("stat local file 'fd:%d' '%s'\n", fd, path);
if(stat(path, st)) {
if(print_err) {
- print_error(0, ERR_SITU_SYNC_STAT_FILE, strerror(errno), path);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_STAT_FAIL, path), strerror(errno));
}
st->st_mode = 0;
return -1;
if(writex(fd, &msg.req, sizeof(msg.req)) ||
writex(fd, path, len)) {
- print_error(1, ERR_SITU_SYNC_STAT_FILE, ERR_REASON_GENERAL_CONNECTION_FAIL, path, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_STAT_FAIL, path), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
if(readx(fd, &msg.stat, sizeof(msg.stat))) {
- print_error(1, ERR_SITU_SYNC_STAT_FILE, ERR_REASON_GENERAL_CONNECTION_FAIL, path, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_STAT_FAIL, path), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
if(msg.stat.id != sync_stat) {
MKCHAR(expected, sync_stat);
MKCHAR(result, msg.stat.id);
- print_error(1, ERR_SITU_SYNC_STAT_FILE, ERR_REASON_GENERAL_PROTOCOL_WRONG_ID, path, expected, result);
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_STAT_FAIL, path), F(ERR_GENERAL_PROTOCOL_WRONG_ID, expected, result));
+
}
st->st_mode = ltohl(msg.stat.mode);
*/
if(!st->st_mode) {
if(print_err) {
- print_error(0, ERR_SITU_SYNC_STAT_FILE, ERR_REASON_GENERAL_UNKNOWN, path);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_STAT_FAIL, path), ERR_GENERAL_UNKNOWN);
}
return -1;
}
fd = sdb_open(srcp, O_RDONLY);
if(fd < 0) {
- print_error(0, ERR_SITU_SYNC_OPEN_FILE, strerror(errno), srcp);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_OPEN_FAIL, srcp), strerror(errno));
return -1;
}
len = strlen(srcp);
if(len > SYNC_CHAR_MAX) {
- print_error(0, ERR_SITU_SYNC_OPEN_FILE, ERR_REASON_GENERAL_PROTOCOL_DATA_OVERRUN, srcp, len, SYNC_CHAR_MAX);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_OPEN_FAIL, srcp), F(ERR_GENERAL_PROTOCOL_DATA_OVERRUN, len, SYNC_CHAR_MAX));
return -1;
}
msg.req.namelen = htoll(len);
if(writex(fd, &msg.req, sizeof(msg.req)) || writex(fd, srcp, len)) {
- print_error(1, ERR_SITU_SYNC_OPEN_FILE, ERR_REASON_GENERAL_CONNECTION_FAIL, srcp, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_OPEN_FAIL, srcp), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
return fd;
}
D("write open local file 'fd:%d' '%s'\n", fd, dstp);
unix_unlink(dstp);
mkdirs(dstp);
+// mkdir(dstp, 0755);
fd = sdb_creat(dstp, 0644);
if(fd < 0) {
- print_error(0, ERR_SITU_SYNC_CREATE_FILE, strerror(errno), dstp);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_CREATE_FAIL, dstp), strerror(errno));
+ D("FAIL to writeopne_local() \n", fd, dstp);
return -1;
}
len = strlen(dstp);
if(len > SYNC_CHAR_MAX) {
- print_error(0, ERR_SITU_SYNC_CREATE_FILE, ERR_REASON_GENERAL_PROTOCOL_DATA_OVERRUN, dstp, len, SYNC_CHAR_MAX);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_CREATE_FAIL, dstp), F(ERR_GENERAL_PROTOCOL_DATA_OVERRUN, len, SYNC_CHAR_MAX));
return -1;
}
if(writex(fd, &msg.req, sizeof(msg.req)) ||
writex(fd, dstp, len) ||
writex(fd, tmp, r)) {
- print_error(1, ERR_SITU_SYNC_OPEN_FILE, ERR_REASON_GENERAL_CONNECTION_FAIL, dstp, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_OPEN_FAIL, dstp), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
return fd;
msg.data.size = htoll(st->st_mtime);
if(writex(fd, &msg.data, sizeof(msg.data))) {
- print_error(1, ERR_SITU_SYNC_CLOSE_FILE, ERR_REASON_GENERAL_CONNECTION_FAIL, dstp, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_CLOSE_FAIL, dstp), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
+
if(readx(fd, &msg.status, sizeof(msg.status))) {
- print_error(1, ERR_SITU_SYNC_CLOSE_FILE, ERR_REASON_GENERAL_CONNECTION_FAIL, dstp, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_CLOSE_FAIL, dstp), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
if(msg.status.id != sync_okay) {
len = 255;
}
if(!readx(fd, buf, len)) {
- print_error(0, ERR_SITU_SYNC_CLOSE_FILE, buf, dstp);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_CLOSE_FAIL, dstp), buf);
return -1;
}
- print_error(1, ERR_SITU_SYNC_CLOSE_FILE, ERR_REASON_GENERAL_UNKNOWN, dstp);
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_CLOSE_FAIL, dstp), ERR_GENERAL_UNKNOWN);
}
char expected[5];
char result[5];
MKCHAR(expected, sync_fail);
MKCHAR(result, msg.status.id);
- print_error(1, ERR_SITU_SYNC_CLOSE_FILE, ERR_REASON_GENERAL_PROTOCOL_WRONG_ID, dstp, expected, result);
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_CLOSE_FAIL, dstp), F(ERR_GENERAL_PROTOCOL_WRONG_ID, expected, result));
}
return fd;
return 2;
}
//fail.
- print_error(0, ERR_SITU_SYNC_READ_FILE, strerror(errno), srcpath);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_READ_FAIL, srcpath), strerror(errno));
return -1;
}
len = readlink(srcpath, sbuf->data, SYNC_DATA_MAX-1);
//fail
if(len < 0) {
- print_error(0, ERR_SITU_SYNC_READ_FILE, strerror(errno), srcpath);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_READ_FAIL, srcpath), strerror(errno));
return -1;
}
sbuf->data[len] = '\0';
//fail
- print_error(0, ERR_SITU_SYNC_READ_FILE, ERR_REASON_SYNC_NOT_FILE, srcpath, srcpath);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_READ_FAIL, srcpath), F(ERR_SYNC_NOT_FILE, srcpath));
return -1;
}
unsigned id;
if(readx(fd, &(msg.data), sizeof(msg.data))) {
- print_error(1, ERR_SITU_SYNC_READ_FILE, ERR_REASON_GENERAL_CONNECTION_FAIL, srcpath, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_READ_FAIL, srcpath), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
id = msg.data.id;
buffer->size = ltohl(msg.data.size);
}
if(!readx(fd, buffer->data, len)) {
buffer->data[len] = 0;
- print_error(0, ERR_SITU_SYNC_READ_FILE, buffer->data, srcpath);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_READ_FAIL, srcpath), buffer->data);
return -1;
}
- print_error(1, ERR_SITU_SYNC_READ_FILE, ERR_REASON_GENERAL_UNKNOWN, srcpath);
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_READ_FAIL, srcpath), ERR_GENERAL_UNKNOWN);
}
char expected[5];
char result[5];
MKCHAR(expected, sync_fail);
MKCHAR(result, id);
- print_error(1, ERR_SITU_SYNC_READ_FILE, ERR_REASON_GENERAL_PROTOCOL_WRONG_ID, srcpath, expected, result);
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_READ_FAIL, srcpath), F(ERR_GENERAL_PROTOCOL_WRONG_ID, expected, result));
}
//fail
if(buffer->size > SYNC_DATA_MAX) {
- print_error(1, ERR_SITU_SYNC_READ_FILE, ERR_REASON_GENERAL_PROTOCOL_DATA_OVERRUN, srcpath, buffer->size, SYNC_DATA_MAX);
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_READ_FAIL, srcpath), F(ERR_GENERAL_PROTOCOL_DATA_OVERRUN, buffer->size, SYNC_DATA_MAX));
}
//fail
if(readx(fd, buffer->data, buffer->size)) {
- print_error(1, ERR_SITU_SYNC_READ_FILE, ERR_REASON_GENERAL_CONNECTION_FAIL, srcpath, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_READ_FAIL, srcpath), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
//write and continue load
* remote channel is already opend
* if local write fails, protocol conflict happens unless we receive sync_done from remote
*/
- print_error(1, ERR_SITU_SYNC_WRITE_FILE, ERR_REASON_GENERAL_CONNECTION_FAIL, dstp, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_WRITE_FAIL, dstp), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
sync_info->total_bytes += len;
int size = ltohl(sbuf->size);
if(writex(fd, sbuf, sizeof(unsigned)*2 + size)) {
- print_error(1, ERR_SITU_SYNC_WRITE_FILE, ERR_REASON_GENERAL_CONNECTION_FAIL, dstp, strerror(errno));
- }
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_WRITE_FAIL, dstp), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
+ }
sync_info->total_bytes += size;
return 0;
d = opendir(src_dir);
if(d == 0) {
- print_error(0, ERR_SITU_SYNC_GET_DIRLIST, strerror(errno), src_dir);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_GET_DIRLIST_FAIL, src_dir), strerror(errno));
readclose_local(fd);
return -1;
}
if(!_stat_local(fd, src_full_path, &src_stat, 1)) {
COPY_INFO* info;
create_copy_info(&info, src_full_path, dst_full_path, &src_stat);
+ D("copy list (destination path) add '%s'\n", dst_full_path);
prepend(dirlist, info);
}
else {
len = strlen(src_dir);
if(len > SYNC_CHAR_MAX) {
- print_error(0, ERR_SITU_SYNC_GET_DIRLIST, ERR_REASON_GENERAL_PROTOCOL_DATA_OVERRUN, src_dir, len, SYNC_CHAR_MAX);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_GET_DIRLIST_FAIL, src_dir), F(ERR_GENERAL_PROTOCOL_DATA_OVERRUN, len, SYNC_CHAR_MAX));
return -1;
}
if(writex(fd, &msg.req, sizeof(msg.req)) ||
writex(fd, src_dir, len)) {
- print_error(1, ERR_SITU_SYNC_GET_DIRLIST, ERR_REASON_GENERAL_CONNECTION_FAIL, src_dir, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_GET_DIRLIST_FAIL, src_dir), strerror(errno));
}
while(1) {
if(readx(fd, &msg.dent, sizeof(msg.dent))) {
- print_error(1, ERR_SITU_SYNC_GET_DIRLIST, ERR_REASON_GENERAL_CONNECTION_FAIL, src_dir, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_GET_DIRLIST_FAIL, src_dir), strerror(errno));
}
if(msg.dent.id == sync_done) {
LOG_INFO("getting list of remote file 'fd:%d' '%s' is done\n", fd, src_dir);
MKCHAR(expected, sync_dent);
MKCHAR(result, msg.dent.id);
- print_error(1, ERR_SITU_SYNC_GET_DIRLIST, ERR_REASON_GENERAL_PROTOCOL_WRONG_ID, src_dir, expected, result);
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_GET_DIRLIST_FAIL, src_dir), F(ERR_GENERAL_PROTOCOL_WRONG_ID, expected, result));
}
len = ltohl(msg.dent.namelen);
if(len > 256) {
- fprintf(stderr,"error: name of a file in the remote directory '%s' exceeds 256\n", src_dir);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_CREATE_FAIL , src_dir), ERR_SYNC_TOO_LONG_FILENAME);
fprintf(stderr,"skipped: %s/? -> %s/?\n", src_dir, dst_dir);
sync_info->skipped++;
continue;
char file_name[257];
if(readx(fd, file_name, len)) {
- print_error(1, ERR_SITU_SYNC_GET_DIRLIST, ERR_REASON_GENERAL_CONNECTION_FAIL, src_dir, strerror(errno));
+ print_error(SDB_MESSAGE_FATAL, F(ERR_SYNC_GET_DIRLIST_FAIL, src_dir), ERR_GENERAL_CONNECTION_FAIL);
+ LOG_ERROR(strerror(errno));
}
file_name[len] = 0;
* We cannot know the reason before we change sync protocol.
*/
if(!st.st_mode) {
- print_error(0, ERR_SITU_SYNC_STAT_FILE, ERR_REASON_GENERAL_UNKNOWN, file_name);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_STAT_FAIL, file_name), ERR_GENERAL_UNKNOWN);
fprintf(stderr,"skipped: %s -> %s\n", src_full_path, dst_full_path);
sync_info->skipped++;
free(src_full_path);
if(fd < 0) {
if(ltype == serverListener) {
- LOG_FATAL("server LN(%d) cannot bind \n", local_port);
+ print_error(SDB_MESSAGE_FATAL, F("server listener(%d) cannot bind", local_port), NULL);
}
else {
- LOG_ERROR("LN(%d) cannot bind \n", local_port);
+ print_error(SDB_MESSAGE_ERROR, F("listener(%d) cannot bind", local_port), NULL);
}
return -2;
}
fflush(stderr);
va_end(args);
}
+void print_error(int level, const char* situation, const char* reason) {
-void print_error(int fatal, const char* situation, const char* reason, ...) {
+ fprintf(stderr, "%s\n", error_message(level, situation, reason));
+ if(level == 1) {
+ fflush(stderr);
+ exit(255);
+ }
+}
+
+char* error_message(int level, const char* situation, const char* reason) {
+ char *format;
+ static char error_buf[255];
+ switch(level){
+ case 0:
+ format = "error";
+ break;
+ case 1:
+ format = "fatal";
+ break;
+ default:
+ format ="sdb";
+ break;
+ }
+
+ if(reason != NULL) {
+ snprintf(error_buf, sizeof(error_buf), "%s: %s: %s", format, situation, reason);
+ } else {
+ snprintf(error_buf, sizeof(error_buf), "%s: %s", format, situation);
+ }
+ return error_buf;
+}
+
+/*
+ * print usage message to user
+ */
+void print_info(const char* message, ...){
+
+ char info_buf_format[INFO_LENGTH];
+
+ char *format = "usage";
- char error_buf_format[ERR_LENGTH];
- snprintf(error_buf_format, ERR_LENGTH, ERR_FORMAT, ERR_TAG, situation, reason);
+ snprintf(info_buf_format, INFO_LENGTH, INFO_FORMAT, format, message);
va_list args;
- va_start(args, reason);
+ va_start(args, message);
- char error_buf[ERR_LENGTH];
- vsnprintf(error_buf, ERR_LENGTH, error_buf_format, args);
- fprintf(stderr, "%s", error_buf);
+ char info_buf[INFO_LENGTH];
+ vsnprintf(info_buf, INFO_LENGTH, info_buf_format, args);
+ fprintf(stdout, "%s\n", info_buf);
va_end(args);
+}
- if(fatal) {
- LOG_ERROR("FATAL\n");
- fflush(stderr);
- exit(255);
- }
+char* F(const char* message, ...) {
+ va_list args;
+ va_start(args, message);
+
+ static char error_buf[255];
+ vsnprintf(error_buf, sizeof(error_buf), message, args);
+
+ va_end(args);
+ return error_buf;
}
static void log_parse(char* args) {
free(levels);
}
-void log_init(void)
+void log_init(void)
{
char* sdb_debug = NULL;
#ifndef __LOG_H
#define __LOG_H
-#define SDB_TRACE 1
-#define DEBUG_ENV "SDB_DEBUG"
-#define TRACE_PACKET "SDB_TRACE_PACKET"
+#define SDB_TRACE 1
+#define DEBUG_ENV "SDB_DEBUG"
+#define TRACE_PACKET "SDB_TRACE_PACKET"
#define ERR_LENGTH 255
-#define ERR_FORMAT "%s: %s: %s\n" //tag:situation:reason
-#define ERR_TAG "sdb"
+#define INFO_LENGTH 255
+#define ERR_FORMAT "%s: %s: %s" //tag:situation:reason
+#define INFO_FORMAT "%s: %s" //tag:message
+//#define ERR_TAG "sdb"
extern int loglevel_mask;
extern int trace_packet;
SDBLOG_FIXME
} LogLevel;
+typedef enum {
+ SDB_MESSAGE_ERROR = 0,
+ SDB_MESSAGE_FATAL
+} MessageLevel;
+
#define LOG_FATAL(args...) \
do { \
logging(SDBLOG_FATAL, __FILE__, __FUNCTION__, __LINE__, args);\
void log_init(void);
void logging(LogLevel level, const char *filename, const char *funcname, int line_number, const char *fmt, ...);
void logging_hex(char* hex, char* asci);
-void print_error(int fatal, const char* situation, const char* reason, ...);
+void print_error(int level, const char* situation, const char* reason);
+char* error_message(int level, const char* situation, const char* reason);
+void print_info(const char* message, ...);
+char* F(const char *message, ...);
// define for a while for testing
#undef D
int complete_checker = atoi(argv[2]);
if(complete_checker == 0) {
- fprintf(stderr, "error:zero_complete_cheker\n");
+ LOG_ERROR("zero_complete_cheker\n");
return -1;
}
if(complete_checker == argc - 3) {
else if(complete_checker == argc - 2) {
return auto_complete(argc - 3, argv + 3, 1);
}
- fprintf(stderr, "error:wrong_complete_cheker\n");
+ LOG_ERROR("wrong-complete_cheker\n");
return -1;
}
#endif
#define TRACE_TAG TRACE_SDB
#include "sdb_client.h"
#include "log.h"
+#include "sdb_messages.h"
static int switch_socket_transport(int fd);
static int __inline__ write_msg_size(int fd, int size, int host_fd);
fprintf(stderr,"error: service name is empty\n");
}
else {
- sendfailmsg(host_fd, "error: service name is empty\n");
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_EMPTY_SERVICE_NAME, NULL);
}
return -1;
}
else if (len > 1024) {
if(host_fd == 0) {
- fprintf(stderr,"error: service name too long\n");
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_TOO_LONG_SERVICE_NAME, NULL);
}
else {
sendfailmsg(host_fd, "error: service name too long\n");
if(writex(fd, service, len)) {
D("error: write failure during connection\n");
if(host_fd == 0) {
- fprintf(stderr,"error: write failure during connection\n");
+ char buf[10];
+ sprintf(buf, "%d", fd);
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_WRITE_FAIL, buf),NULL);
}
else {
sendfailmsg(host_fd, "error: write failure during connection\n");
if(readx(fd, buf, 4)) {
if(host_fd == 0) {
- fprintf(stderr,"error: protocol fault (no status)\n");
+ print_error(SDB_MESSAGE_ERROR, "protocol fault", "no status");
}
else {
sendfailmsg(host_fd, "error: protocol fault (no status)\n");
if(memcmp(buf, "FAIL", 4)) {
if(host_fd == 0) {
- fprintf(stderr,"error: protocol fault (status %02x %02x %02x %02x?!)\n",
- buf[0], buf[1], buf[2], buf[3]);
+ print_error(SDB_MESSAGE_ERROR, "protocol fault", F("status %02x %02x %02x %02x?!", buf[0], buf[1], buf[2], buf[3]));
}
else {
char err_msg[255];
int len = read_msg_size(fd);
if(len < 0) {
if(host_fd == 0) {
- fprintf(stderr,"error: protocol fault (status len)\n");
+ print_error(SDB_MESSAGE_ERROR, "protocol fault", "status len");
}
else {
sendfailmsg(host_fd, "error: protocol fault (status len)\n");
char error[255];
if(readx(fd, error, len)) {
if(host_fd == 0) {
- fprintf(stderr,"error: protocol fault (status read)\n");
+ print_error(SDB_MESSAGE_ERROR, "protocol fault", "status read");
}
else {
sendfailmsg(host_fd, "error: protocol fault (status read)\n");
}
error[len] = '\0';
if(host_fd == 0) {
- fprintf(stderr,"error msg: %s\n", error);
+ fprintf(stderr,"%s\n", error);
}
else {
char err_msg[255];
if(writex(fd, tmp, 4)) {
D("error: write msg size failure\n");
if(host_fd == 0) {
- fprintf(stderr,"error: write msg size failure\n");
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_WRITE_MESSAGE_SIZE_FAIL, NULL);
}
else {
sendfailmsg(host_fd, "error: write msg size failure\n");
int patch = strtoul(tokens[2], 0, 10);
if (major != SDB_VERSION_MAJOR || minor != SDB_VERSION_MINOR || patch != SDB_VERSION_PATCH ) {
fprintf(stdout,
- "* sdb (%s) already running, and restarting sdb(%d.%d.%d) again *\n",
+ "* sdb (%s) already running, and restarting sdb (%d.%d.%d) again *\n",
buf, SDB_VERSION_MAJOR, SDB_VERSION_MINOR,
SDB_VERSION_PATCH);
restarting = 1;
} else {
if (ver != SDB_VERSION_PATCH) {
fprintf(stdout,
- "* another version of sdb already running, and restarting sdb(%d.%d.%d) again *\n",
+ "* another version of sdb already running, and restarting sdb (%d.%d.%d) again *\n",
SDB_VERSION_MAJOR, SDB_VERSION_MINOR, SDB_VERSION_PATCH);
restarting = 1;
}
}
if(fd == -2) {
- fprintf(stdout,"* daemon not running. starting it now on port %d *\n", DEFAULT_SDB_PORT);
+ fprintf(stdout,"* server not running. starting it now on port %d *\n", DEFAULT_SDB_PORT);
launch_server:
if(launch_server()) {
- fprintf(stderr,"* failed to start daemon *\n");
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_START_SERVER_FAIL, NULL);
return -1;
} else {
- fprintf(stdout,"* daemon started successfully *\n");
+ fprintf(stdout,"* server started successfully *\n");
}
}
fd = _sdb_connect(service);
if(fd == -2) {
- fprintf(stderr,"** daemon still not running\n");
+ print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_SERVER_NOT_RUN, NULL);
}
D("sdb_connect: return fd %d\n", fd);
const int COMMANDLINE_FORWARD_REMOVE_ALL_MAX_ARG = 0;
const int COMMANDLINE_FORWARD_REMOVE_ALL_MIN_ARG = 0;
+ const char* COMMANDLINE_FORWARDLIST_NAME = "forward-list";
+ const char* COMMANDLINE_FORWARDLIST_DESC[] = {
+ "list forwarding ports",
+ };
+ const int COMMANDLINE_FORWARDLIST_DESC_SIZE = GET_ARRAY_SIZE(COMMANDLINE_FORWARDLIST_DESC, char*);
+ const int COMMANDLINE_FORWARDLIST_MAX_ARG = 0;
+ const int COMMANDLINE_FORWARDLIST_MIN_ARG = 0;
+
const char* COMMANDLINE_PUSH_NAME = "push";
const char* COMMANDLINE_PUSH_DESC[] = {
"copy file/dir to device",
const char* STATE_LOCKED = "locked";
const char* STATE_UNKNOWN = "unknown";
const char* STATE_SUSPENDED = "suspended";
-
- const char* ERR_REASON_GENERAL_PROTOCOL_WRONG_ID = "protocol error. expected '%s' but get '%s'";
- const char* ERR_REASON_GENERAL_PROTOCOL_DATA_OVERRUN = "protocol error. data length '%d' overruns '%d'";
- const char* ERR_REASON_GENERAL_CONNECTION_FAIL = "connection fails. %s";
- const char* ERR_REASON_GENERAL_UNKNOWN = "unknown reason";
- const char* ERR_REASON_SYNC_NOT_FILE = "'%s' is not a file";
-
- const char* ERR_SITU_SYNC_OPEN_CHANNEL = "fail to open sync channel";
- const char* ERR_SITU_SYNC_STAT_FILE = "fail to stat '%s'";
- const char* ERR_SITU_SYNC_GET_DIRLIST = "fail to read dirlist of '%s'";
- const char* ERR_SITU_SYNC_READ_FILE = "fail to read '%s'";
- const char* ERR_SITU_SYNC_OPEN_FILE = "fail to open '%s'";
- const char* ERR_SITU_SYNC_CREATE_FILE = "fail to create '%s'";
- const char* ERR_SITU_SYNC_CLOSE_FILE = "fail to close '%s'";
- const char* ERR_SITU_SYNC_WRITE_FILE = "fail to write '%s'";
-
- const char* ERR_TRANSPORT_MORE_THAN_ONE_TARGET = "error: there are more than one target. Please specify the target using -s option.";
- const char* ERR_TRANSPORT_MORE_THAN_ONE_EMUL = "error: there are more than one emulator. Please specify the emulator using -s option.";
- const char* ERR_TRANSPORT_MORE_THAN_ONE_DEV = "error: there are more than one device. Please specify the device using -s option.";
- const char* ERR_TRANSPORT_TARGET_OFFLINE = "error: target offline";
- const char* ERR_TRANSPORT_TARGET_SUSPENDED = "error: emulator is in suspended mode";
- const char* ERR_TRANSPORT_TARGET_NOT_FOUND = "error: target not found";
-
- const char* ERR_FORWARD_UNKNOWN_LOCAL_PORT = "error: wrong local port format";
- const char* ERR_FORWARD_UNKNOWN_REMOTE_PORT = "error: wrong remote port format";
- const char* ERR_FORWARD_INSTALL_FAIL = "error: cannot install listener";
- const char* ERR_FORWARD_REMOVE_FAIL = "error: cannot remove listener";
typedef enum host_type HOST_TYPE;
+// extern const char* SDB = "sdb";
+// extern const char* SDB_FULL = "Smart Development Bridge";
+
extern const char* SDB_LAUNCH_SCRIPT;
extern const char* HELP_APPEND_STR;
extern const char* STATE_UNKNOWN;
extern const char* STATE_SUSPENDED;
- extern const char* ERR_REASON_GENERAL_PROTOCOL_WRONG_ID;
- extern const char* ERR_REASON_GENERAL_PROTOCOL_DATA_OVERRUN;
- extern const char* ERR_REASON_GENERAL_CONNECTION_FAIL;
- extern const char* ERR_REASON_GENERAL_UNKNOWN;
- extern const char* ERR_REASON_SYNC_NOT_FILE;
-
- extern const char* ERR_SITU_SYNC_OPEN_CHANNEL;
- extern const char* ERR_SITU_SYNC_STAT_FILE;
- extern const char* ERR_SITU_SYNC_GET_DIRLIST;
- extern const char* ERR_SITU_SYNC_READ_FILE;
- extern const char* ERR_SITU_SYNC_OPEN_FILE;
- extern const char* ERR_SITU_SYNC_CREATE_FILE;
- extern const char* ERR_SITU_SYNC_CLOSE_FILE;
- extern const char* ERR_SITU_SYNC_WRITE_FILE;
-
- extern const char* ERR_TRANSPORT_MORE_THAN_ONE_TARGET;
- extern const char* ERR_TRANSPORT_MORE_THAN_ONE_EMUL;
- extern const char* ERR_TRANSPORT_MORE_THAN_ONE_DEV;
- extern const char* ERR_TRANSPORT_TARGET_OFFLINE;
- extern const char* ERR_TRANSPORT_TARGET_SUSPENDED;
- extern const char* ERR_TRANSPORT_TARGET_NOT_FOUND;
-
- extern const char* ERR_FORWARD_UNKNOWN_LOCAL_PORT;
- extern const char* ERR_FORWARD_UNKNOWN_REMOTE_PORT;
- extern const char* ERR_FORWARD_INSTALL_FAIL;
- extern const char* ERR_FORWARD_REMOVE_FAIL;
-
#endif /* SDB_CONSTANTS_H_*/
--- /dev/null
+/*
+ * SDB - Smart Development Bridge
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Shingil Kang <shingil.kang@samsung.com>
+ * Yoonki Park <yoonki.park@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+#include "sdb_messages.h"
+
+const char* NO_ERR = "no error, successful exit";
+const char* ERR_GENERAL_CONNECTION_FAIL = "connection fails";
+const char* ERR_GENERAL_UNKNOWN = "unknown reason";
+const char* ERR_GENERAL_INITIALIZE_ENV_FAIL = "failed to initialize SBD environment";
+const char* ERR_GENERAL_EMPTY_SERVICE_NAME = "empty service name";
+const char* ERR_GENERAL_TOO_LONG_SERVICE_NAME = "service name too long";
+const char* ERR_GENERAL_INVALID_SERVICE_NAME = "invalid service name";
+const char* ERR_GENERAL_WRITE_MESSAGE_SIZE_FAIL = "failed to write message size";
+const char* ERR_GENERAL_INVALID_PORT = "invalid port '%s'";
+const char* ERR_GENERAL_START_SERVER_FAIL = "failed to start server";
+const char* ERR_GENERAL_SERVER_NOT_RUN = "server not running";
+const char* ERR_GENERAL_LOG_FAIL = "failed to log";
+const char* ERR_GENERAL_DUPLICATE_FAIL = "failed to duplicate '%s'";
+const char* ERR_GENERAL_LAUNCH_APP_FAIL = "failed to launch application";
+const char* ERR_GENERAL_KILL_SERVER_FAIL = "failed to kill server";
+const char* ERR_GENERAL_SET_FD_FAIL = "cannot set the FD status";
+const char* ERR_GENERAL_INVALID_IP = "invalid IP '%s'";
+const char* ERR_GENERAL_NO_READ_PERMISSION = "no read permission";
+const char* ERR_GENERAL_NO_WRITE_PERMISSION = "no write permission";
+const char* ERR_GENERAL_NO_EXECUTE_PERMISSION = "no execute permission";
+const char* ERR_GENERAL_PROTOCOL_WRONG_ID = "protocol error; expected '%s' but got '%s'";
+const char* ERR_GENERAL_PROTOCOL_DATA_OVERRUN = "protocol error; data length '%d' overruns '%d'";
+
+const char* ERR_SYNC_NOT_FILE = "'%s' is not a file";
+const char* ERR_SYNC_OPEN_CHANNEL_FAIL = "failed to open sync channel";
+const char* ERR_SYNC_STAT_FAIL = "failed to get status of '%s'";
+const char* ERR_SYNC_GET_DIRLIST_FAIL = "failed to read directory list of '%s'";
+const char* ERR_SYNC_READ_FAIL = "failed to read '%s'";
+const char* ERR_SYNC_OPEN_FAIL = "failed to open '%s'";
+const char* ERR_SYNC_CREATE_FAIL = "failed to create '%s'";
+const char* ERR_SYNC_CLOSE_FAIL = "failed to close '%s'";
+const char* ERR_SYNC_WRITE_FAIL = "failed to write '%s'";
+const char* ERR_SYNC_COPY_FAIL = "failed to copy";
+const char* ERR_SYNC_TOO_LONG_FILENAME = "file name too long";
+const char* ERR_SYNC_INVALID_FILENAME = "invalid file name";
+const char* ERR_SYNC_UNKNOWN_TYPE_FILE = "invalid file type";
+const char* ERR_SYNC_NOT_EXIST_FILE = "'%s' does not exist";
+const char* ERR_SYNC_NOT_DIRECTORY = "'%s' is not a directory";
+const char* ERR_SYNC_LOCKED = "'%s' is locked";
+const char* ERR_SYNC_CANNOT_ACCESS = "cannot access '%s'";
+
+const char* ERR_CONNECT_MORE_THAN_ONE_TARGET = "more than one target found. Specify the target with -s option.";
+const char* ERR_CONNECT_MORE_THAN_ONE_EMUL = "more than one emulator found. Specify the emulator with -e option.";
+const char* ERR_CONNECT_MORE_THAN_ONE_DEV = "more than one device found. Specify the device with -d option.";
+const char* ERR_CONNECT_TARGET_NOT_FOUND = "target not found";
+const char* ERR_CONNECT_TARGET_OFFLINE = "target offline";
+const char* ERR_CONNECT_TARGET_LOCKED = "target locked";
+const char* ERR_CONNECT_TARGET_SUSPENDED = "target suspended";
+const char* ERR_CONNECT_CONNECT_REMOTE_TARGET_FAILED = "failed to connect to remote target '%s'";
+const char* ERR_CONNECT_TARGET_NO_RESPONSE = "no response from target";
+const char* ERR_CONNECT_WRONG_SERIAL = "serial number '%s' wrong";
+
+const char* ERR_COMMAND_MISSING_ARGUMENT = "missing arguments for '%s' command";
+const char* ERR_COMMAND_TOO_FEW_ARGUMENTS = "too few arguments";
+const char* ERR_COMMAND_TOO_MANY_ARGUMENTS = "too many arguments";
+const char* ERR_COMMAND_RUN_COMMAND_FAILED = "failed to run command";
+const char* ERR_COMMAND_COMMAND_NO_SUPPORT = "command '%s' not supported";
+const char* ERR_COMMAND_OPTION_NO_SUPPORT = "option '%s' not supported";
+const char* ERR_COMMAND_OPTION_MUST_HAVE_ARGUMENT = "option '%s' must have an argument";
+const char* ERR_FORWARD_UNSUPPORT_TRANSMISSION_PROTOCOL = "unsupported transmission protocol";
+const char* ERR_FORWARD_INSTALL_FAIL = "cannot install forward listener";
+const char* ERR_FORWARD_REMOVE_FAIL = "cannot remove forward listener";
+const char* ERR_FORWARD_INVALID_PROTOCOL = "invalid protocol";
+const char* ERR_FORWARD_BIND_PORT_FAIL = "failed to bind port '%s'";
+const char* ERR_PACKAGE_TYPE_UNKNOWN = "package type unknown";
+const char* ERR_PACKAGE_GET_TEMP_PATH_FAIL = "failed to get package temporary path";
+const char* ERR_PACKAGE_GET_TYPE_FAIL = "failed to get package type";
+const char* ERR_PACKAGE_ID_NOT_EXIST = "package ID '%s' does not exist";
+const char* ERR_PACKAGE_ID_NOT_UNIQUE = "package ID '%s' not unique";
+const char* ERR_LAUNCH_M_OPTION_SUPPORT = "In DA and Oprofile, the -m option is supported in sdbd higher than 2.2.0";
+const char* ERR_LAUNCH_M_OPTION_ARGUMENT = "The -m option accepts arguments only for run or debug options";
+const char* ERR_LAUNCH_P_OPTION_DEBUG_MODE = "The -P option must be used in debug mode";
+const char* ERR_LAUNCH_ATTACH_OPTION_DEBUG_MODE = "The -attach option must be used in debug mode";
--- /dev/null
+/*
+* SDB - Smart Development Bridge
+*
+* Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Shingil Kang <shingil.kang@samsung.com>
+* Yoonki Park <yoonki.park@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+#ifndef SDB_MESSAGES_H_
+#define SDB_MESSAGES_H_
+
+extern const char* NO_ERR;
+extern const char* ERR_GENERAL_CONNECTION_FAIL;
+extern const char* ERR_GENERAL_UNKNOWN;
+extern const char* ERR_GENERAL_INITIALIZE_ENV_FAIL;
+extern const char* ERR_GENERAL_EMPTY_SERVICE_NAME;
+extern const char* ERR_GENERAL_TOO_LONG_SERVICE_NAME;
+extern const char* ERR_GENERAL_INVALID_SERVICE_NAME;
+extern const char* ERR_GENERAL_WRITE_MESSAGE_SIZE_FAIL;
+extern const char* ERR_GENERAL_INVALID_PORT;
+extern const char* ERR_GENERAL_START_SERVER_FAIL;
+extern const char* ERR_GENERAL_SERVER_NOT_RUN;
+extern const char* ERR_GENERAL_LOG_FAIL;
+extern const char* ERR_GENERAL_DUPLICATE_FAIL;
+extern const char* ERR_GENERAL_LAUNCH_APP_FAIL;
+extern const char* ERR_GENERAL_KILL_SERVER_FAIL;
+extern const char* ERR_GENERAL_SET_FD_FAIL;
+extern const char* ERR_GENERAL_INVALID_IP;
+extern const char* ERR_GENERAL_NO_READ_PERMISSION;
+extern const char* ERR_GENERAL_NO_WRITE_PERMISSION;
+extern const char* ERR_GENERAL_NO_EXECUTE_PERMISSION;
+extern const char* ERR_GENERAL_PROTOCOL_WRONG_ID;
+extern const char* ERR_GENERAL_PROTOCOL_DATA_OVERRUN;
+
+extern const char* ERR_SYNC_NOT_FILE;
+extern const char* ERR_SYNC_OPEN_CHANNEL_FAIL;
+extern const char* ERR_SYNC_STAT_FAIL;
+extern const char* ERR_SYNC_GET_DIRLIST_FAIL;
+extern const char* ERR_SYNC_READ_FAIL;
+extern const char* ERR_SYNC_OPEN_FAIL;
+extern const char* ERR_SYNC_CREATE_FAIL;
+extern const char* ERR_SYNC_CLOSE_FAIL;
+extern const char* ERR_SYNC_WRITE_FAIL;
+extern const char* ERR_SYNC_COPY_FAIL;
+extern const char* ERR_SYNC_TOO_LONG_FILENAME;
+extern const char* ERR_SYNC_INVALID_FILENAME;
+extern const char* ERR_SYNC_UNKNOWN_TYPE_FILE;
+extern const char* ERR_SYNC_NOT_EXIST_FILE;
+extern const char* ERR_SYNC_NOT_DIRECTORY;
+extern const char* ERR_SYNC_LOCKED;
+extern const char* ERR_SYNC_CANNOT_ACCESS;
+
+extern const char* ERR_CONNECT_MORE_THAN_ONE_TARGET;
+extern const char* ERR_CONNECT_MORE_THAN_ONE_EMUL;
+extern const char* ERR_CONNECT_MORE_THAN_ONE_DEV;
+extern const char* ERR_CONNECT_TARGET_NOT_FOUND;
+extern const char* ERR_CONNECT_TARGET_OFFLINE;
+extern const char* ERR_CONNECT_TARGET_LOCKED;
+extern const char* ERR_CONNECT_TARGET_SUSPENDED;
+extern const char* ERR_CONNECT_CONNECT_REMOTE_TARGET_FAILED;
+extern const char* ERR_CONNECT_TARGET_NO_RESPONSE;
+extern const char* ERR_CONNECT_WRONG_SERIAL;
+
+extern const char* ERR_COMMAND_MISSING_ARGUMENT;
+extern const char* ERR_COMMAND_TOO_FEW_ARGUMENTS;
+extern const char* ERR_COMMAND_TOO_MANY_ARGUMENTS;
+extern const char* ERR_COMMAND_RUN_COMMAND_FAILED;
+extern const char* ERR_COMMAND_COMMAND_NO_SUPPORT;
+extern const char* ERR_COMMAND_OPTION_NO_SUPPORT;
+extern const char* ERR_COMMAND_OPTION_MUST_HAVE_ARGUMENT;
+extern const char* ERR_FORWARD_UNSUPPORT_TRANSMISSION_PROTOCOL;
+extern const char* ERR_FORWARD_INSTALL_FAIL;
+extern const char* ERR_FORWARD_REMOVE_FAIL;
+extern const char* ERR_FORWARD_INVALID_PROTOCOL;
+extern const char* ERR_FORWARD_BIND_PORT_FAIL;
+extern const char* ERR_PACKAGE_TYPE_UNKNOWN;
+extern const char* ERR_PACKAGE_GET_TEMP_PATH_FAIL;
+extern const char* ERR_PACKAGE_GET_TYPE_FAIL;
+extern const char* ERR_PACKAGE_ID_NOT_EXIST;
+extern const char* ERR_PACKAGE_ID_NOT_UNIQUE;
+extern const char* ERR_LAUNCH_M_OPTION_SUPPORT;
+extern const char* ERR_LAUNCH_M_OPTION_ARGUMENT;
+extern const char* ERR_LAUNCH_P_OPTION_DEBUG_MODE;
+extern const char* ERR_LAUNCH_ATTACH_OPTION_DEBUG_MODE;
+
+#endif /* SDB_MESSAGE_H_ */
#include "sdb_model.h"
#include "linkedlist.h"
#include "log.h"
+#include "sdb_messages.h"
const COMMAND NULL_COMMAND = {
NULL,
D("Parse option: %s with longname %d\n", name, longname);
OPTION* option = get_option(opt_list, name, longname);
if(option == NULL) {
- fprintf(stderr, "unrecognized option: %s\n", name);
+ print_error(SDB_MESSAGE_ERROR, ERR_COMMAND_RUN_COMMAND_FAILED, F(ERR_COMMAND_OPTION_NO_SUPPORT, name));
return -1;
}
local_pass_arg++;
}
else {
- fprintf(stderr, "option: %s should have a argument\n", name);
+ print_error(SDB_MESSAGE_ERROR, ERR_COMMAND_RUN_COMMAND_FAILED, F(ERR_COMMAND_OPTION_MUST_HAVE_ARGUMENT, name));
+ print_info(ERR_COMMAND_OPTION_MUST_HAVE_ARGUMENT, name);
return -1;
}
}
}
int null_function (int argc, char** argv) {
- fprintf(stderr, "unsupported command: %s\n", argv[0]);
+ print_error(SDB_MESSAGE_ERROR, ERR_COMMAND_RUN_COMMAND_FAILED, F(ERR_COMMAND_COMMAND_NO_SUPPORT, argv[0]));
return -1;
}
#include "log.h"
#include "listener.h"
#include "sdb.h"
+#include "sdb_messages.h"
#define TRACE_TAG TRACE_SOCKETS
char* serial = host_str + prefix_len;
char* end = strchr(serial, ':');
if(end == NULL) {
- *err_str = (char*)ERR_TRANSPORT_TARGET_NOT_FOUND;
+ *err_str = error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_TARGET_NOT_FOUND, NULL);
return 0;
}
local = strtok(request, ";");
remote = strtok(NULL , ";");
if(remote == 0 || remote[1] == '\0') {
- forward_err = "malformed forward spec";
+ forward_err = error_message(SDB_MESSAGE_ERROR, ERR_FORWARD_INVALID_PROTOCOL, NULL);
goto sendfail;
}
if(strncmp("tcp:", remote, 4)){
- forward_err = (char*)ERR_FORWARD_UNKNOWN_REMOTE_PORT;
+ forward_err = error_message(SDB_MESSAGE_ERROR, ERR_FORWARD_UNSUPPORT_TRANSMISSION_PROTOCOL, NULL);
goto sendfail;
}
if (t == NULL || t->connection_state == CS_OFFLINE) {
if(t != NULL) {
- forward_err = (char*)ERR_TRANSPORT_TARGET_OFFLINE;
+ forward_err = error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_TARGET_OFFLINE, NULL);
}
else {
forward_err = err_str;
}
if(strncmp("tcp:", local, 4)){
- forward_err = (char*)ERR_FORWARD_UNKNOWN_LOCAL_PORT;
+ forward_err = error_message(SDB_MESSAGE_ERROR, ERR_FORWARD_UNSUPPORT_TRANSMISSION_PROTOCOL, NULL);
goto sendfail;
}
return 0;
}
else {
- forward_err = (char*)ERR_FORWARD_INSTALL_FAIL;
+ forward_err = error_message(SDB_MESSAGE_ERROR, ERR_FORWARD_INSTALL_FAIL, NULL);
goto sendfail;
}
} else if (forward == 15) {
writex(socket->fd, "OKAYOKAY", 8);
return 0;
} else {
- forward_err = (char*)ERR_FORWARD_REMOVE_FAIL;
+ forward_err = error_message(SDB_MESSAGE_ERROR, ERR_FORWARD_REMOVE_FAIL, NULL);
goto sendfail;
}
}
LISTENER* l = currentptr->data;
if (l->type == forwardListener) {
if(remove_listener(l->local_port)){
- forward_err = (char*)ERR_FORWARD_REMOVE_FAIL;
+ forward_err = error_message(SDB_MESSAGE_ERROR, ERR_FORWARD_REMOVE_FAIL, NULL);
goto sendfail;
}
}
if (nr == 1 && match) {
*serial_out = strdup(match);
} else if (nr == 0) {
- asprintf(serial_out, "device not found");
+ asprintf(serial_out, error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_TARGET_NOT_FOUND, NULL));
} else if (nr > 1) {
- asprintf(serial_out, "more than one device and emulator");
+ asprintf(serial_out, error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_MORE_THAN_ONE_TARGET, NULL));
}
return nr;
cmd_buf[0] = '\0';
kick_transport(t);
} else {
- snprintf(cmd_buf, cbuf_size, "No such device %s", serial);
+ snprintf(cmd_buf, cbuf_size, error_message(SDB_MESSAGE_ERROR, F("remote target '%s' not connected", serial), NULL));
}
} else {
unregister_all_tcp_transports();
if(result == 1) {
return result;
- }
+ }
char* host_str = (char *)p->data + 4;
char *service = NULL;
char* err_str = NULL;
} else {
if(t != NULL) {
if(t->suspended) {
- err_str =(char*)ERR_TRANSPORT_TARGET_SUSPENDED;
+ err_str = error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_TARGET_SUSPENDED, NULL);
}
else {
- err_str = (char*)ERR_TRANSPORT_TARGET_OFFLINE;
+ err_str = error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_TARGET_OFFLINE, NULL);
}
}
LOG_ERROR("LS(%X) get no transport", s->local_id);
int fd = sdb_host_connect(host, port, SOCK_STREAM);
if (fd < 0) {
- snprintf(buf, buf_len, "fail to connect to %s", host);
+ snprintf(buf, buf_len, error_message(SDB_MESSAGE_ERROR, F(ERR_CONNECT_CONNECT_REMOTE_TARGET_FAILED, host), NULL));
return;
}
#include "memutils.h"
#include "listener.h"
#include "log.h"
+#include "sdb_messages.h"
#define TRACE_TAG TRACE_TRANSPORT
}
}
+
void
kick_transport(TRANSPORT* t)
{
}
}
-
void dump_packet(const char* name, const char* func, PACKET* p)
{
if(trace_packet) {
} else {
if(ttype == kTransportAny) {
if (result) {
- *error_out = (char*)ERR_TRANSPORT_MORE_THAN_ONE_TARGET;
+ *error_out = error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_MORE_THAN_ONE_TARGET, NULL);
result = NULL;
goto exit;
}
(ttype == kTransportLocal && transport_->type == kTransportConnect)) {
if (result) {
if(ttype == kTransportUsb) {
- *error_out = (char*)ERR_TRANSPORT_MORE_THAN_ONE_DEV;
+ *error_out = error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_MORE_THAN_ONE_DEV, NULL);
}
else if(ttype == kTransportLocal) {
- *error_out = (char*)ERR_TRANSPORT_MORE_THAN_ONE_EMUL;
+ *error_out = error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_MORE_THAN_ONE_EMUL, NULL);
}
result = NULL;
goto exit;
}
if (result == NULL ) {
- *error_out = (char*)ERR_TRANSPORT_TARGET_NOT_FOUND;
+ *error_out = error_message(SDB_MESSAGE_ERROR, ERR_CONNECT_TARGET_NOT_FOUND, NULL);
}
exit:
#include "fdevent.h"
#include "sdb_constants.h"
#include "strutils.h"
+#include "sdb_messages.h"
#define TRACE_TAG TRACE_SDB
}
#endif
- fprintf(stderr,"cannot stat '%s': %s\n", path, strerror(errno));
+ print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_STAT_FAIL, path), strerror(errno));
return -1;
}
#define TRACE_TAG TRACE_SYSDEPS
#include "utils_backend.h"
#include "log.h"
+#include "sdb_messages.h"
static int _launch_server(void)
{
switch (pid = fork()) {
case -1:
- fprintf(stderr, "Couldn't fork: %s\n", strerror(errno));
+ LOG_ERROR("failed to fork process: %s\n", strerror(errno));
return -1;
// never reached!
case 0: {
setsid();
execl(path, "sdb", "fork-server", "server", NULL);
- fprintf(stderr, "Couldn't exec: '%s'\n", strerror(errno));
+ LOG_ERROR("failed to execute process: %s\n", strerror(errno));
_exit(-1);
}
default:
fd = unix_open("/tmp/sdb.log", O_WRONLY | O_CREAT | O_APPEND, 0640);
if(fd < 0) {
- fprintf(stderr, "fail to open '/tmp/sdb.log' logging fails\n");
+ print_error(SDB_MESSAGE_ERROR ,ERR_GENERAL_LOG_FAIL, F(ERR_SYNC_OPEN_FAIL, "/tmp/sdb/log"));
fd = unix_open("/dev/null", O_WRONLY);
if( fd < 0 ) {
- fprintf(stderr, "fail to open /dev/null\n");
- fprintf(stderr,"--- sdb starting (pid %d) ---\n", getpid());
+ print_error(SDB_MESSAGE_ERROR ,ERR_GENERAL_LOG_FAIL, F(ERR_SYNC_OPEN_FAIL, "/dev/null"));
+ LOG_DEBUG("--- sdb starting (pid %d) ---\n", getpid());
return;
}
}
dup2(fd, 2);
sdb_close(fd);
- fprintf(stderr,"--- sdb starting (pid %d) ---\n", getpid());
+ LOG_DEBUG("--- sdb starting (pid %d) ---\n", getpid());
+ return;
+
}
static char* _ansi_to_utf8(const char *str)
{
int ret = fcntl( fd, F_SETFD, FD_CLOEXEC );
if (ret == -1)
- fprintf(stderr, "fail to set the file descriptor to be closed when the process executes another program\n");
+ LOG_ERROR("failed to set the file descriptor '%d': %s",fd ,strerror(errno));
}
static int _sdb_open( const char* pathname, int options )
int on = 1;
int ret = setsockopt( fd, IPPROTO_TCP, TCP_NODELAY, (void*)&on, sizeof(on) );
if (ret == -1)
- fprintf(stderr, "fail to set level option of FD(%d)", fd);
+ LOG_ERROR("failed to set the file descriptor '%d': %s\n", fd, strerror(errno));
}
static int _sdb_thread_create( sdb_thread_t *pthread, sdb_thread_func_t start, void* arg )
n = 1;
int ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n));
if (ret == -1)
- fprintf(stderr, "fail to set level option of FD(%d)", s);
+ LOG_ERROR("failed to set the file descriptor '%d': %s\n", s, strerror(errno));
if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
sdb_close(s);