File: disman-script-mib-proc.c

package info (click to toggle)
scli 0.3.1-3.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,872 kB
  • ctags: 8,627
  • sloc: ansic: 32,657; sh: 7,388; makefile: 321
file content (103 lines) | stat: -rw-r--r-- 3,606 bytes parent folder | download
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
/* 
 * disman-script-mib-proc.c -- DISMAN-SCRIPT-MIB procedures
 *
 * Copyright (C) 2001 Juergen Schoenwaelder
 *
 * 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, or (at your option)
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * 
 * @(#) $Id: disman-script-mib-proc.c 1995 2006-08-22 21:58:46Z schoenw $
 */

#include "snmpv2-tc.h"

#include "disman-script-mib-proc.h"

void
disman_script_mib_proc_create_script(GNetSnmp *s,
				     guchar *owner,
				     guchar *name,
				     guchar *descr)
{
    disman_script_mib_smScriptEntry_t *smScriptEntry;
    gint32 createAndGo = SNMPV2_TC_ROWSTATUS_CREATEANDGO;
    
    smScriptEntry = disman_script_mib_new_smScriptEntry();
    if (! smScriptEntry) {
	s->error_status = GNET_SNMP_PDU_ERR_PROCEDURE;
	return;
    }
    strcpy(smScriptEntry->smScriptOwner, owner);
    smScriptEntry->_smScriptOwnerLength = strlen(owner);
    strcpy(smScriptEntry->smScriptName, name);
    smScriptEntry->_smScriptNameLength = strlen(name);
    smScriptEntry->smScriptDescr = descr;
    smScriptEntry->_smScriptDescrLength = strlen(descr);
    smScriptEntry->smScriptRowStatus = &createAndGo;
    disman_script_mib_set_smScriptEntry(s, smScriptEntry, 0);
    disman_script_mib_free_smScriptEntry(smScriptEntry);
}


/*
 * This implements the procedure described in section 7.6 of RFC 3165.
 */

void
disman_script_mib_proc_create_run(GNetSnmp *s,
				  guchar *lowner,
				  guchar *lname,
				  guchar *args)
{
    disman_script_mib_smLaunchEntry_t *smLaunchEntry;
    disman_script_mib_smRunEntry_t *smRunEntry;
    gint32 smRunIndex;
    int i, done = 0;

    disman_script_mib_get_smLaunchEntry(s, &smLaunchEntry,
					lowner, strlen(lowner),
					lname, strlen(lname),
					DISMAN_SCRIPT_MIB_SMLAUNCHRUNINDEXNEXT);
    if (s->error_status) return;
    if (!smLaunchEntry || !smLaunchEntry->smLaunchRunIndexNext) {
    proc_error:
	s->error_status = GNET_SNMP_PDU_ERR_PROCEDURE;
	return;
    }
    smRunIndex = *smLaunchEntry->smLaunchRunIndexNext;
    smLaunchEntry->smLaunchArgument = args;
    smLaunchEntry->_smLaunchArgumentLength = args ? strlen(args) : 0;
    smLaunchEntry->smLaunchStart = &smRunIndex;
    disman_script_mib_set_smLaunchEntry(s, smLaunchEntry,
					DISMAN_SCRIPT_MIB_SMLAUNCHSTART
					| DISMAN_SCRIPT_MIB_SMLAUNCHARGUMENT);
    disman_script_mib_free_smLaunchEntry(smLaunchEntry);
    if (s->error_status) return;
    for (i = 0; i < 5 && ! done; i++) {
	disman_script_mib_get_smRunEntry(s, &smRunEntry,
					 lowner, strlen(lowner),
					 lname, strlen(lname),
					 smRunIndex,
					 DISMAN_SCRIPT_MIB_SMRUNSTATE);
	if (s->error_status) return;	/* oops - cleanup ? */
	if (! smRunEntry) goto proc_error;
	done = ! smRunEntry->smRunState
	    || *smRunEntry->smRunState == DISMAN_SCRIPT_MIB_SMRUNSTATE_EXECUTING
	    || *smRunEntry->smRunState == DISMAN_SCRIPT_MIB_SMRUNSTATE_SUSPENDED
	    || *smRunEntry->smRunState == DISMAN_SCRIPT_MIB_SMRUNSTATE_TERMINATED;
	    
	disman_script_mib_free_smRunEntry(smRunEntry);
    }
    if (! done) goto proc_error;
}