Segmentation fault while using bash script to generate mobility file

1.7k Views Asked by At

I am using a bash script to generate mobility files (setdest) in ns2 for various seeds. But I am running into this troublesome segmentation fault. Any help would be appreciated. The setdest.cc has been modified, so its not the standard ns2 file.

I will walk you through the problem.

This code in a shell script returns the segmentation fault.

#! /bin/sh
setdest="/root/ns-allinone-2.1b9a/ns-2.1b9a/indep-utils/cmu-scen-gen/setdest/setdest_mesh_seed_mod"
let nn="70" #Number of nodes in the simulation
let time="900"  #Simulation time
let x="1000"    #Horizontal dimensions
let y="1000"    #Vertical dimensions


for speed in 5
do
for pause in 10 
do
for seed in 1 5
do
echo -e "\n"
echo  Seed = $seed Speed = $speed Pause Time = $pause 
chmod 700 $setdest
setdest -n $nn -p $pause -s $speed -t $time -x $x -y $y -l 1 -m 50 > scen-mesh-n$nn-seed$seed-p$pause-s$speed-t$time-x$x-y$y
done
done
done

error is

scengen_mesh: line 21: 14144 Segmentation fault      $setdest -n $nn -p $pause -s $speed -t $time -x $x -y $y -l 1 -m 50 >scen-mesh-n$nn-seed$seed-p$pause-s$speed-t$time-x$x-y$y

line 21 is the last line of the shell script (done)

The strange thing is If i run the same setdest command on the terminal, there is no problem! like $setdest -n 70 -p 10 -s 5 -t 900 -x 1000 -y 1000 -l 1 -m 50

I have made out where the problem is exactly. Its with the argument -l. If i remove the argument in the shell script, there is no problem. Now i will walk you through the modified setdest.cc where this argument is coming from.

This modified setdest file uses a text file initpos to read XY coordinates of static nodes for a wireless mesh topology. the relevant lines of code are

FILE *fp_loc;
int locinit;

fp_loc = fopen("initpos","r");

while ((ch = getopt(argc, argv, "r:m:l:n:p:s:t:x:y:i:o")) != EOF) {       

switch (ch) {
case 'l': 
    locinit = atoi(optarg);
    break;
default:
    usage(argv);
    exit(1);

if(locinit)
    fscanf(fp_loc,"%lf %lf",&position.X, &position.Y);
if (position.X == -1 && position.Y == -1){
        position.X = uniform() * MAXX;
        position.Y = uniform() * MAXY;
    }

What i dont get is... In Shell script.. -option -l if supplied by 0 returns no error, -but if supplied by any other value (i used 1 mostly) returns this segmentation fault. In Terminal.. -no segmentation fault with any value. 0 or 1

something to do with the shell script surely. I am amazed what is going wrong where!

Your help will be highly appreciated. Cheers

0

There are 0 best solutions below