1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/******************************************************************************
(c) 1998-2000 Christine Caulfield christine.caulfield@googlemail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
******************************************************************************
*/
// submit.cc
// Code for a SUBMIT task within a FAL server process.
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <syslog.h>
#include <limits.h>
#include <pwd.h>
#include <grp.h>
#include <glob.h>
#include <regex.h>
#include <string.h>
#include <netdnet/dn.h>
#include <netdnet/dnetdb.h>
#include "logging.h"
#include "connection.h"
#include "protocol.h"
#include "vaxcrc.h"
#include "params.h"
#include "task.h"
#include "server.h"
#include "submit.h"
#ifndef SUBMIT_COMMAND
#define SUBMIT_COMMAND "at -f %s now "
#endif
fal_submit::fal_submit(dap_connection &c, int v, fal_params &p):
fal_task(c,v,p)
{
}
fal_submit::~fal_submit()
{
}
bool fal_submit::process_message(dap_message *m)
{
if (verbose > 2) DAPLOG((LOG_DEBUG, "in fal_submit::process_message\n"));
switch (m->get_type())
{
case dap_message::ACCESS:
{
glob_t gl;
int status;
int pathno = 0;
char unixname[PATH_MAX];
dap_access_message *am = (dap_access_message *)m;
// Convert the name if necessary
if (is_vms_name(am->get_filespec()))
{
make_unix_filespec(unixname, am->get_filespec());
}
else
{
strcpy(unixname, am->get_filespec());
add_vroot(unixname);
}
// Create the list of files
status = glob(unixname, 0, NULL, &gl);
if (status)
{
// glob does not return errno codes
switch (status)
{
case GLOB_NOSPACE:
return_error(ENOMEM);
break;
#ifdef GLOB_ABORTED
case GLOB_ABORTED:
#else
case GLOB_ABEND:
#endif
return_error(EIO);
break;
#ifdef GLOB_NOMATCH
case GLOB_NOMATCH:
return_error(ENOENT);
break;
#endif
default:
return_error();
break;
}
return false;
}
conn.set_blocked(true);
if (gl.gl_pathc == 1)
{
if (!send_file_attributes(gl.gl_pathv[0], am->get_display(),
SEND_DEV))
{
return_error();
return false;
}
}
// Submit all the files
do
{
char cmd[PATH_MAX + strlen(SUBMIT_COMMAND)+1];
sprintf(cmd, SUBMIT_COMMAND, gl.gl_pathv[pathno]);
status = system(cmd);
if (verbose > 1)
DAPLOG((LOG_DEBUG, "in fal_submit: '%s', result = %d\n", gl.gl_pathv[pathno], status));
pathno++;
} while (status == 0 && gl.gl_pathv[pathno]);
if (status) // Send error code
{
return_error();
}
else
{
dap_accomp_message acc;
acc.set_cmpfunc(dap_accomp_message::RESPONSE);
acc.write(conn);
}
globfree(&gl);
if (!conn.set_blocked(false)) return false;
}
}
return false; //Finished
}
|