~ubuntu-branches/debian/stretch/jfsutils/stretch

« back to all changes in this revision

Viewing changes to fsck/fsckruns.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Hornburg (Racke)
  • Date: 2005-01-07 10:12:20 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050107101220-ka3f7smw42zysmk1
Tags: 1.1.7-1
* new upstream release (Closes: #289106)
* start synopsis with lowercase

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *   Copyright (c) International Business Machines  Corp., 2000
 
2
 *   Copyright (c) International Business Machines Corp., 2000-2002
3
3
 *
4
4
 *   This program is free software;  you can redistribute it and/or modify
5
5
 *   it under the terms of the GNU General Public License as published by
6
 
 *   the Free Software Foundation; either version 2 of the License, or
 
6
 *   the Free Software Foundation; either version 2 of the License, or 
7
7
 *   (at your option) any later version.
8
 
 *
 
8
 * 
9
9
 *   This program is distributed in the hope that it will be useful,
10
10
 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
11
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12
12
 *   the GNU General Public License for more details.
13
13
 *
14
14
 *   You should have received a copy of the GNU General Public License
15
 
 *   along with this program;  if not, write to the Free Software
 
15
 *   along with this program;  if not, write to the Free Software 
16
16
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
 
 *
18
 
 *   MODULE_NAME:               fsckruns.c
19
 
 *
20
 
 *   COMPONENT_NAME:    jfs utilities
21
 
 *
22
 
 *   FUNCTIONS:
23
 
 *              fsck_hbeat
24
 
 *              fsck_hbeat_start
25
 
 *              fsck_hbeat_stop
26
 
 *
27
 
 */
28
 
 
29
 
#define INCL_DOSPROCESS
30
 
 
31
 
/*
32
 
 * defines and includes common among the xfsck modules
33
 
 */
 
17
 */
 
18
/* defines and includes common among the fsck.jfs modules */
34
19
#include "xfsckint.h"
35
20
 
36
21
#include <unistd.h>
37
 
#include <pthread.h>
 
22
#include <signal.h>
38
23
 
39
24
extern char *MsgText[];
40
25
 
41
 
char hb_message_buffer[256];
42
 
char *hb_msg_ptr = &hb_message_buffer[0];
43
 
 
44
 
 /* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
45
 
  *
46
 
  * For managing the heartbeat thread
47
 
  *
48
 
  * defined in xchkdsk.c
49
 
  *
50
 
  */
51
 
void * fsck_hbeat ( void * );
52
 
 
53
 
static pthread_t        tidHbeatThread = 0;     
54
 
int volatile            exit_flag = 0;
55
 
 
56
26
/*****************************************************************************
57
27
 * NAME: fsck_hbeat
58
28
 *
60
30
 *
61
31
 * PARAMETERS:  none
62
32
 *
63
 
 * NOTES:       
 
33
 * NOTES:
 
34
 *      This is racy, but we don't care.
64
35
 *
65
36
 * RETURNS:
66
37
 *      success: FSCK_OK
67
38
 *      failure: something else
68
39
 */
69
 
void * fsck_hbeat ( void * Initial_Value )
 
40
void fsck_hbeat(int unused)
70
41
{
71
 
 
72
 
  unsigned long current_heartbeat = *((unsigned long *) Initial_Value);
73
 
 
74
 
  while( exit_flag == 0 ) {
75
 
        
76
 
    sleep( 1);  /* sleep for a second */
77
 
        
78
 
    switch( current_heartbeat ) {
79
 
          case 0:
80
 
            sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT0] );
81
 
            current_heartbeat = 1;
82
 
          break;
83
 
          case 1:
84
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT1] );
85
 
                current_heartbeat = 2;
86
 
          break;
87
 
          case 2:
88
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT2] );
89
 
                current_heartbeat = 3;
90
 
          break;
91
 
          case 3:
92
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT3] );
93
 
                current_heartbeat = 4;
94
 
          break;
95
 
          case 4:
96
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT4] );
97
 
                current_heartbeat = 5;
98
 
          break;
99
 
          case 5:
100
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT5] );
101
 
                current_heartbeat = 6;
102
 
          break;
103
 
          case 6:
104
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT6] );
105
 
                current_heartbeat = 7;
106
 
          break;
107
 
          case 7:
108
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT7] );
109
 
                current_heartbeat = 8;
110
 
          break;
111
 
          case 8:
112
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT8] );
113
 
                current_heartbeat = 9;
114
 
          break;
115
 
          case 9:
116
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT7] );
117
 
                current_heartbeat = 10;
118
 
          break;
119
 
          case 10:
120
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT6] );
121
 
                current_heartbeat = 11;
122
 
          break;
123
 
          case 11:
124
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT5] );
125
 
                current_heartbeat = 12;
126
 
          break;
127
 
          case 12:
128
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT4] );
129
 
                current_heartbeat = 13;
130
 
          break;
131
 
          case 13:
132
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT3] );
133
 
                current_heartbeat = 14;
134
 
          break;
135
 
          case 14:
136
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT2] );
137
 
                current_heartbeat = 15;
138
 
          break;
139
 
          case 15:
140
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT1] );
 
42
        static volatile unsigned long current_heartbeat = 0;
 
43
 
 
44
        switch (current_heartbeat) {
 
45
        case 0:
 
46
                printf("%s", msg_defs[fsck_HEARTBEAT0].msg_txt);
 
47
                current_heartbeat++;
 
48
                break;
 
49
        case 1:
 
50
                printf("%s", msg_defs[fsck_HEARTBEAT1].msg_txt);
 
51
                current_heartbeat++;
 
52
                break;
 
53
        case 2:
 
54
                printf("%s", msg_defs[fsck_HEARTBEAT2].msg_txt);
 
55
                current_heartbeat++;
 
56
                break;
 
57
        case 3:
 
58
                printf("%s", msg_defs[fsck_HEARTBEAT3].msg_txt);
 
59
                current_heartbeat++;
 
60
                break;
 
61
        case 4:
 
62
                printf("%s", msg_defs[fsck_HEARTBEAT4].msg_txt);
 
63
                current_heartbeat++;
 
64
                break;
 
65
        case 5:
 
66
                printf("%s", msg_defs[fsck_HEARTBEAT5].msg_txt);
 
67
                current_heartbeat++;
 
68
                break;
 
69
        case 6:
 
70
                printf("%s", msg_defs[fsck_HEARTBEAT6].msg_txt);
 
71
                current_heartbeat++;
 
72
                break;
 
73
        case 7:
 
74
                printf("%s", msg_defs[fsck_HEARTBEAT7].msg_txt);
 
75
                current_heartbeat++;
 
76
                break;
 
77
        case 8:
 
78
                printf("%s", msg_defs[fsck_HEARTBEAT8].msg_txt);
 
79
                current_heartbeat++;
 
80
                break;
 
81
        case 9:
 
82
                printf("%s", msg_defs[fsck_HEARTBEAT7].msg_txt);
 
83
                current_heartbeat++;
 
84
                break;
 
85
        case 10:
 
86
                printf("%s", msg_defs[fsck_HEARTBEAT6].msg_txt);
 
87
                current_heartbeat++;
 
88
                break;
 
89
        case 11:
 
90
                printf("%s", msg_defs[fsck_HEARTBEAT5].msg_txt);
 
91
                current_heartbeat++;
 
92
                break;
 
93
        case 12:
 
94
                printf("%s", msg_defs[fsck_HEARTBEAT4].msg_txt);
 
95
                current_heartbeat++;
 
96
                break;
 
97
        case 13:
 
98
                printf("%s", msg_defs[fsck_HEARTBEAT3].msg_txt);
 
99
                current_heartbeat++;
 
100
                break;
 
101
        case 14:
 
102
                printf("%s", msg_defs[fsck_HEARTBEAT2].msg_txt);
 
103
                current_heartbeat++;
 
104
                break;
 
105
        case 15:
 
106
                printf("%s", msg_defs[fsck_HEARTBEAT1].msg_txt);
141
107
                current_heartbeat = 0;
142
 
          break;
143
 
          default:
144
 
                sprintf( hb_msg_ptr, MsgText[fsck_HEARTBEAT0] );
 
108
                break;
 
109
        default:
 
110
                printf("%s", msg_defs[fsck_HEARTBEAT0].msg_txt);
145
111
                current_heartbeat = 1;
146
112
        }
147
113
 
148
 
        printf("%s", hb_msg_ptr );
149
 
        fflush( stdout );
150
 
        
151
 
  }  /* end while */
152
 
 
153
 
  exit_flag = 0;
154
 
 
155
 
  /* Exit the thread. */
156
 
  pthread_exit(NULL);
157
 
        
158
 
  return NULL;
159
 
}  /* end of fsck_hbeat() */
160
 
        
161
 
        
 
114
        fflush(stdout);
 
115
        alarm(1);
 
116
}
 
117
 
162
118
/*****************************************************************************
163
119
 * NAME: fsck_hbeat_start
164
120
 *
166
122
 *
167
123
 * PARAMETERS:  none
168
124
 *
169
 
 * NOTES:       
170
 
 *
171
125
 * RETURNS:
172
126
 *      success: FSCK_OK
173
127
 *      failure: something else
174
128
 */
175
 
void fsck_hbeat_start ( )
 
129
void fsck_hbeat_start(void)
176
130
{
177
 
  int            rc;
178
 
  unsigned long  ulThreadParm = 0;
179
 
        
180
 
  rc = pthread_create( &tidHbeatThread, NULL, &fsck_hbeat, &ulThreadParm);
181
 
        
182
 
  if( rc != NO_ERROR ) {
183
 
    tidHbeatThread = 0;
184
 
  }
185
 
        
186
 
  return;
187
 
}  /* end of fsck_hbeat_start() */
188
 
        
189
 
        
 
131
        struct sigaction sa;
 
132
 
 
133
        memset(&sa, 0, sizeof (sa));
 
134
        sa.sa_handler = &fsck_hbeat;
 
135
        sa.sa_flags = SA_RESTART;
 
136
 
 
137
        sigaction(SIGALRM, &sa, NULL);
 
138
        alarm(1);
 
139
}
 
140
 
190
141
/*****************************************************************************
191
142
 * NAME: fsck_hbeat_stop
192
143
 *
194
145
 *
195
146
 * PARAMETERS:  none
196
147
 *
197
 
 * NOTES:       
198
 
 *
199
148
 * RETURNS:
200
149
 *      success: FSCK_OK
201
150
 *      failure: something else
202
151
 */
203
 
void fsck_hbeat_stop ( )
 
152
void fsck_hbeat_stop(void)
204
153
{
205
 
 
206
 
  exit_flag = -1;
207
 
        
208
 
        /*
209
 
         * try 5 times to kill the heartbeat thread
210
 
         */
211
 
  while( exit_flag != 0 ) {
212
 
        sleep(1);
213
 
  }
214
 
        
215
 
  return;
216
 
}  /* end of fsck_hbeat_stop() */
 
154
        struct sigaction sa;
 
155
 
 
156
        memset(&sa, 0, sizeof (sa));
 
157
        sa.sa_handler = SIG_DFL;
 
158
 
 
159
        sigaction(SIGALRM, &sa, NULL);
 
160
        alarm(0);
 
161
}