1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
35
#include <sys/types.h>
42
#include "sge_signal.h"
43
#include "msg_common.h"
45
#include "sge_unistd.h"
47
int sge_edit(const char *fname, uid_t myuid, gid_t mygid)
49
SGE_STRUCT_STAT before, after;
54
DENTER(TOP_LAYER, "sge_edit");;
57
ERROR((SGE_EVENT, MSG_NULLPOINTER));
61
if (SGE_STAT(fname, &before)) {
62
ERROR((SGE_EVENT, MSG_FILE_EDITFILEXDOESNOTEXIST_S, fname));
67
chown(fname, myuid, mygid);
72
ws = waitpid(pid, &status, 0);
73
if (WIFEXITED(status)) {
74
if (WEXITSTATUS(status) != 0) {
75
ERROR((SGE_EVENT, MSG_QCONF_EDITOREXITEDWITHERROR_I,
76
(int) WEXITSTATUS(status)));
81
if (SGE_STAT(fname, &after)) {
82
ERROR((SGE_EVENT, MSG_QCONF_EDITFILEXNOLONGEREXISTS_S, fname));
86
if ((before.st_mtime != after.st_mtime) ||
87
(before.st_size != after.st_size)) {
92
/* file is unchanged; inform caller */
98
#ifndef WIN32 /* signals b18 */
99
if (WIFSIGNALED(status)) {
100
ERROR((SGE_EVENT, MSG_QCONF_EDITORWASTERMINATEDBYSIGX_I,
101
(int) WTERMSIG(status)));
108
const char *cp = NULL;
110
sge_set_def_sig_mask(NULL, NULL);
111
sge_unblock_all_signals();
115
cp = sge_getenv("EDITOR");
116
if (!cp || strlen(cp) == 0)
119
execlp(cp, cp, fname, (char *) 0);
120
ERROR((SGE_EVENT, MSG_QCONF_CANTSTARTEDITORX_S, cp));