Skip to content

Commit

Permalink
Cleaned up code style in 'movecommand' patchset
Browse files Browse the repository at this point in the history
Updated coding style as reported by scripts/checkpatch.pl

Signed-off-by: Mark Harvey <markh794@gmail.com>
  • Loading branch information
markh794 committed Apr 26, 2012
1 parent 4f89b71 commit c9e92b3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
25 changes: 14 additions & 11 deletions usr/smc.c
Expand Up @@ -1069,12 +1069,12 @@ static int run_move_command(struct smc_priv *smc_p, struct s_info *src,
int cmdlen;

if (!smc_p->movecommand) {
// no command: do nothing
/* no command: do nothing */
return SAM_STAT_GOOD;
}

cmdlen = strlen(smc_p->movecommand)+MAX_BARCODE_LEN+4*10;
movecommand = malloc(cmdlen+1);
movecommand = malloc(cmdlen + 1);

if (!movecommand) {
MHVTL_ERR("malloc failed");
Expand All @@ -1084,17 +1084,17 @@ static int run_move_command(struct smc_priv *smc_p, struct s_info *src,

sprintf(barcode, "%s", src->media->barcode);
truncate_spaces(&barcode[0], MAX_BARCODE_LEN + 1);
snprintf(movecommand,cmdlen,"%s %s %d %s %d %s",
snprintf(movecommand, cmdlen, "%s %s %d %s %d %s",
smc_p->movecommand,
slot_type_str[src->element_type],
slot_number(src),
slot_type_str[dest->element_type],
slot_number(dest),
barcode
);
res = run_command(movecommand,smc_p->commandtimeout);
res = run_command(movecommand, smc_p->commandtimeout);
if (res) {
MHVTL_ERR("move command returned %d",res);
MHVTL_ERR("move command returned %d", res);
mkSenseBuf(HARDWARE_ERROR, E_MANUAL_INTERVENTION_REQ, sam_stat);
return SAM_STAT_CHECK_CONDITION;
}
Expand Down Expand Up @@ -1167,7 +1167,8 @@ static int move_slot2drive(struct smc_priv *smc_p,
}

retval = run_move_command(smc_p, src, dest->slot, sam_stat);
if (retval) return retval;
if (retval)
return retval;
move_cart(src, dest->slot);
setDriveFull(dest);

Expand Down Expand Up @@ -1233,7 +1234,8 @@ static int move_slot2slot(struct smc_priv *smc_p, int src_addr,
}

retval = run_move_command(smc_p, src, dest, sam_stat);
if (retval) return retval;
if (retval)
return retval;
move_cart(src, dest);
return retval;
}
Expand Down Expand Up @@ -1310,7 +1312,8 @@ static int move_drive2slot(struct smc_priv *smc_p,
}

retval = run_move_command(smc_p, src->slot, dest, sam_stat);
if (retval) return retval;
if (retval)
return retval;
move_cart(src->slot, dest);
setDriveEmpty(src);

Expand Down Expand Up @@ -1348,7 +1351,8 @@ static int move_drive2drive(struct smc_priv *smc_p,
send_msg("unload", src->drv_id);

retval = run_move_command(smc_p, src->slot, dest->slot, sam_stat);
if (retval) return retval;
if (retval)
return retval;
move_cart(src->slot, dest->slot);

sprintf(cmd, "lload %s", dest->slot->media->barcode);
Expand Down Expand Up @@ -1599,4 +1603,3 @@ uint8_t smc_log_sense(struct scsi_cmd *cmd)
mkSenseBuf(ILLEGAL_REQUEST, E_INVALID_FIELD_IN_CDB, sam_stat);
return SAM_STAT_CHECK_CONDITION;
}

34 changes: 17 additions & 17 deletions usr/subprocess.c
Expand Up @@ -32,46 +32,46 @@
#include "logging.h"

static pid_t pid;
static int timedout = 0;
static int timedout;

void alarm_timeout(int sig) {
void alarm_timeout(int sig)
{
alarm(0);
timedout=1;
if (pid) kill(pid,9);
timedout = 1;
if (pid)
kill(pid, 9);
}

int run_command(char* command,int timeout) {

int run_command(char *command, int timeout)
{
pid = fork();
if (!pid) {
// child
execlp("/bin/sh","/bin/sh","-c",command,(char *)NULL);
/* child */
execlp("/bin/sh", "/bin/sh", "-c", command, (char *)NULL);
} else if (pid < 0) {
// TODO error handling
/* TODO error handling */
return -1;
} else {
signal(SIGALRM,alarm_timeout);
signal(SIGALRM, alarm_timeout);
timedout = 0;
alarm(timeout);
int status;
while (waitpid(pid,&status,0) <= 0) {

while (waitpid(pid, &status, 0) <= 0)
usleep(1);
}

alarm(0);

if (WIFEXITED(status)) {
int res = WEXITSTATUS(status);
return res;
} else if (WIFSIGNALED(status)) {
int sig = WTERMSIG(status);
//MHVTL_LOG("command died with signal: %d (timedout: %d)\n",sig,timedout);
MHVTL_DBG(1, "command died with signal: %d "
"(timedout: %d)\n", sig, timedout);
return -sig;
}
}

return -1;

}



2 changes: 1 addition & 1 deletion usr/subprocess.h
@@ -1,2 +1,2 @@

int run_command(char* command,int timeout);
int run_command(char *command, int timeout);
4 changes: 2 additions & 2 deletions usr/vtllibrary.c
Expand Up @@ -1061,10 +1061,10 @@ static int init_lu(struct lu_phy_attr *lu, int minor, struct vtl_ctl *ctl)
process_fifoname(lu, s, 0);

if (sscanf(b, " movecommand: %s", s))
smc_slots.movecommand=strndup(s,MALLOC_SZ);
smc_slots.movecommand = strndup(s, MALLOC_SZ);

if (sscanf(b, " commandtimeout: %d", &d))
smc_slots.commandtimeout=d;
smc_slots.commandtimeout = d;

i = sscanf(b,
" NAA: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
Expand Down

0 comments on commit c9e92b3

Please sign in to comment.