| 1 |
/* File: VMS_CRTL_INIT.C |
| 2 |
|
| 3 |
This file is common to a lot of projects. |
| 4 |
|
| 5 |
$Id: vms_crtl_init.c,v 1.1.1.1 2012/12/02 19:25:22 wb8tyw Exp $ |
| 6 |
|
| 7 |
Module that provides a LIB$INITIALIZE routine for the GNV toolset that |
| 8 |
will turn on some CRTL features that are not enabled by default. |
| 9 |
|
| 10 |
The CRTL features can also be turned on via logical names, but that |
| 11 |
impacts all programs and some aren't ready, willing, or able to handle |
| 12 |
the settings that GNV needs. |
| 13 |
|
| 14 |
The original module was found linked with GPL V2 modules, and thus must |
| 15 |
be able to be distributed under the GPL V2 provisions. |
| 16 |
|
| 17 |
As this module or similar is needed for virtually all programs built to run |
| 18 |
under GNV or UNIX, it can be distributed with other licenses. |
| 19 |
|
| 20 |
Edit History |
| 21 |
|
| 22 |
1-001 John Reagan Initial version using the old style interface |
| 23 |
but with the new version commented out. |
| 24 |
|
| 25 |
1-002 John Reagan Switch to new API for setting features |
| 26 |
|
| 27 |
1-003 Steve Pitcher Add DECC$RENAME_NO_INHERIT. |
| 28 |
|
| 29 |
1-004 Steve Pitcher Quiet these, if the DECC feature doesn't exist. |
| 30 |
|
| 31 |
2-001 J. Malmberg New GNV requirements: |
| 32 |
Three variations of object modules: |
| 33 |
1. For use with shells, sets the logical |
| 34 |
name GNV$UNIX_SHELL. |
| 35 |
|
| 36 |
2. For utilities, if the logical name |
| 37 |
GNV$UNIX_SHELL is set, it means that the |
| 38 |
settings should assume that they are |
| 39 |
running under a UNIX like shell. |
| 40 |
|
| 41 |
3. A third setting is for utilities that |
| 42 |
always should behave as if they are |
| 43 |
running under a UNIX shell. |
| 44 |
|
| 45 |
If GNV$GNU is defined, then locally define |
| 46 |
SYS$POSIX_ROOT to it. GNV$GNU can be set in |
| 47 |
the SYSTEM table by the GNV setup. |
| 48 |
SYS$POSIX_ROOT can not. |
| 49 |
|
| 50 |
The logical name BIN also needs to be defined |
| 51 |
here, otherwise the CRTL replaces it with |
| 52 |
SYS$SYSTEM: |
| 53 |
|
| 54 |
Never set the POSIX UID here, it will break |
| 55 |
every reference to a GID/UID on systems that |
| 56 |
do not have every VMS account mapped to a UID/GID |
| 57 |
by TCPIP services. |
| 58 |
|
| 59 |
Reformat text to fit 80 columns. |
| 60 |
|
| 61 |
Remove all VAX C specific code. |
| 62 |
|
| 63 |
Linker is probably using exact case, so public |
| 64 |
symbols for LIB$* and SYS$* must be in upper case. |
| 65 |
|
| 66 |
2-002 J. Malmberg Support for VAX builds. OpenVMS/VAX does not have the |
| 67 |
17-Jun-2010 DECC$FEATURE routines. At this time I will not |
| 68 |
be concerned if a feature setting exists on VAX, |
| 69 |
as all we are doing is setting a logical name. |
| 70 |
|
| 71 |
2-003 J. Malmberg Add DECC$FILENAME_UNIX_NOVERSION as version numbers |
| 72 |
will usually mess up ported programs. |
| 73 |
|
| 74 |
*/ |
| 75 |
|
| 76 |
#include <stdio.h> |
| 77 |
#include <descrip.h> |
| 78 |
#include <lnmdef.h> |
| 79 |
#include <stsdef.h> |
| 80 |
#include <string.h> |
| 81 |
|
| 82 |
#pragma message disable pragma |
| 83 |
#pragma message disable dollarid |
| 84 |
#pragma message disable valuepres |
| 85 |
|
| 86 |
#pragma member_alignment save |
| 87 |
#pragma nomember_alignment longword |
| 88 |
#pragma message save |
| 89 |
#pragma message disable misalgndmem |
| 90 |
struct itmlst_3 { |
| 91 |
unsigned short int buflen; |
| 92 |
unsigned short int itmcode; |
| 93 |
void *bufadr; |
| 94 |
unsigned short int *retlen; |
| 95 |
}; |
| 96 |
#pragma message restore |
| 97 |
#pragma member_alignment restore |
| 98 |
|
| 99 |
#ifdef __VAX |
| 100 |
#define ENABLE "ENABLE" |
| 101 |
#define DISABLE "DISABLE" |
| 102 |
#else |
| 103 |
|
| 104 |
#define ENABLE TRUE |
| 105 |
#define DISABLE 0 |
| 106 |
int decc$feature_get_index (const char *name); |
| 107 |
int decc$feature_set_value (int index, int mode, int value); |
| 108 |
|
| 109 |
#endif |
| 110 |
|
| 111 |
int SYS$TRNLNM( |
| 112 |
const unsigned long * attr, |
| 113 |
const struct dsc$descriptor_s * table_dsc, |
| 114 |
struct dsc$descriptor_s * name_dsc, |
| 115 |
const unsigned char * acmode, |
| 116 |
const struct itmlst_3 * item_list); |
| 117 |
int SYS$CRELNM( |
| 118 |
const unsigned long * attr, |
| 119 |
const struct dsc$descriptor_s * table_dsc, |
| 120 |
const struct dsc$descriptor_s * name_dsc, |
| 121 |
const unsigned char * acmode, |
| 122 |
const struct itmlst_3 * item_list); |
| 123 |
int LIB$SIGNAL(int); |
| 124 |
|
| 125 |
/* Take all the fun out of simply looking up a logical name */ |
| 126 |
static int sys_trnlnm |
| 127 |
(const char * logname, |
| 128 |
char * value, |
| 129 |
int value_len) |
| 130 |
{ |
| 131 |
const $DESCRIPTOR(table_dsc, "LNM$FILE_DEV"); |
| 132 |
const unsigned long attr = LNM$M_CASE_BLIND; |
| 133 |
struct dsc$descriptor_s name_dsc; |
| 134 |
int status; |
| 135 |
unsigned short result; |
| 136 |
struct itmlst_3 itlst[2]; |
| 137 |
|
| 138 |
itlst[0].buflen = value_len; |
| 139 |
itlst[0].itmcode = LNM$_STRING; |
| 140 |
itlst[0].bufadr = value; |
| 141 |
itlst[0].retlen = &result; |
| 142 |
|
| 143 |
itlst[1].buflen = 0; |
| 144 |
itlst[1].itmcode = 0; |
| 145 |
|
| 146 |
name_dsc.dsc$w_length = strlen(logname); |
| 147 |
name_dsc.dsc$a_pointer = (char *)logname; |
| 148 |
name_dsc.dsc$b_dtype = DSC$K_DTYPE_T; |
| 149 |
name_dsc.dsc$b_class = DSC$K_CLASS_S; |
| 150 |
|
| 151 |
status = SYS$TRNLNM(&attr, &table_dsc, &name_dsc, 0, itlst); |
| 152 |
|
| 153 |
if ($VMS_STATUS_SUCCESS(status)) { |
| 154 |
|
| 155 |
/* Null terminate and return the string */ |
| 156 |
/*--------------------------------------*/ |
| 157 |
value[result] = '\0'; |
| 158 |
} |
| 159 |
|
| 160 |
return status; |
| 161 |
} |
| 162 |
|
| 163 |
/* How to simply create a logical name */ |
| 164 |
static int sys_crelnm |
| 165 |
(const char * logname, |
| 166 |
const char * value) |
| 167 |
{ |
| 168 |
int ret_val; |
| 169 |
const char * proc_table = "LNM$PROCESS_TABLE"; |
| 170 |
struct dsc$descriptor_s proc_table_dsc; |
| 171 |
struct dsc$descriptor_s logname_dsc; |
| 172 |
struct itmlst_3 item_list[2]; |
| 173 |
|
| 174 |
proc_table_dsc.dsc$a_pointer = (char *) proc_table; |
| 175 |
proc_table_dsc.dsc$w_length = strlen(proc_table); |
| 176 |
proc_table_dsc.dsc$b_dtype = DSC$K_DTYPE_T; |
| 177 |
proc_table_dsc.dsc$b_class = DSC$K_CLASS_S; |
| 178 |
|
| 179 |
logname_dsc.dsc$a_pointer = (char *) logname; |
| 180 |
logname_dsc.dsc$w_length = strlen(logname); |
| 181 |
logname_dsc.dsc$b_dtype = DSC$K_DTYPE_T; |
| 182 |
logname_dsc.dsc$b_class = DSC$K_CLASS_S; |
| 183 |
|
| 184 |
item_list[0].buflen = strlen(value); |
| 185 |
item_list[0].itmcode = LNM$_STRING; |
| 186 |
item_list[0].bufadr = (char *)value; |
| 187 |
item_list[0].retlen = NULL; |
| 188 |
|
| 189 |
item_list[1].buflen = 0; |
| 190 |
item_list[1].itmcode = 0; |
| 191 |
|
| 192 |
ret_val = SYS$CRELNM(NULL, &proc_table_dsc, &logname_dsc, NULL, item_list); |
| 193 |
|
| 194 |
return ret_val; |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
/* Start of DECC RTL Feature handling */ |
| 199 |
|
| 200 |
/* |
| 201 |
** Sets default value for a feature |
| 202 |
*/ |
| 203 |
#ifdef __VAX |
| 204 |
static void set_feature_default(const char *name, const char *value) |
| 205 |
{ |
| 206 |
sys_crelnm(name, value); |
| 207 |
} |
| 208 |
#else |
| 209 |
static void set_feature_default(const char *name, int value) |
| 210 |
{ |
| 211 |
int index; |
| 212 |
|
| 213 |
index = decc$feature_get_index(name); |
| 214 |
|
| 215 |
if (index > 0) |
| 216 |
decc$feature_set_value (index, 0, value); |
| 217 |
} |
| 218 |
#endif |
| 219 |
|
| 220 |
static void set_coe ( void ) |
| 221 |
{ |
| 222 |
|
| 223 |
char gnv_posix_root[4096]; |
| 224 |
char unix_shell_name[255]; |
| 225 |
int use_unix_settings = 0; |
| 226 |
int status; |
| 227 |
int gnv_posix_root_found = 0; |
| 228 |
|
| 229 |
/* If this is compiled for use with a UNIX shell, then the logical |
| 230 |
* name GNV$UNIX_SHELL will be set to that shell name. |
| 231 |
* |
| 232 |
* Else, if the GNV$UNIX_SHELL logical name is set, then this application |
| 233 |
* is running under some UNIX like shell, so it should modify it's |
| 234 |
* behavior to be UNIX like. |
| 235 |
* |
| 236 |
* If the above logical name is not set, then the application should |
| 237 |
* expect that it is running under DCL, and should expect VMS filenames |
| 238 |
* on input, and may need to output filenames in VMS format. |
| 239 |
* |
| 240 |
* This can be overriden at compile time with GNV_UNIX_TOOL being |
| 241 |
* defined. |
| 242 |
* |
| 243 |
* So this means that there will be multiple object modules from this |
| 244 |
* source module. One for each shell, one for programs that can function |
| 245 |
* in both DCL and UNIX environments, and one for programs that require |
| 246 |
* a UNIX environment. |
| 247 |
*/ |
| 248 |
|
| 249 |
#ifdef GNV_UNIX_SHELL |
| 250 |
use_unix_settings = 1; |
| 251 |
|
| 252 |
status = sys_crelnm("GNV$UNIX_SHELL", GNV_UNIX_SHELL); |
| 253 |
if (!$VMS_STATUS_SUCCESS(status)) { |
| 254 |
/* We have a big problem */ |
| 255 |
LIB$SIGNAL(status); |
| 256 |
} |
| 257 |
#else |
| 258 |
|
| 259 |
#ifdef GNV_UNIX_TOOL |
| 260 |
use_unix_settings = 1; |
| 261 |
#else |
| 262 |
status = sys_trnlnm("GNV$UNIX_SHELL", |
| 263 |
unix_shell_name, sizeof |
| 264 |
unix_shell_name -1); |
| 265 |
if (!$VMS_STATUS_SUCCESS(status)) { |
| 266 |
unix_shell_name[0] = 0; |
| 267 |
use_unix_settings = 0; |
| 268 |
} |
| 269 |
#endif /* GNV_UNIX_TOOL */ |
| 270 |
|
| 271 |
#endif /* GNV_UNIX_SHELL */ |
| 272 |
|
| 273 |
/* New style interface that works only on very recent |
| 274 |
(Apr 2001 and beyond) CRTLs */ |
| 275 |
|
| 276 |
/* |
| 277 |
* Only setting defaults allows logical names to |
| 278 |
* override these settings. |
| 279 |
*/ |
| 280 |
|
| 281 |
/* Always set */ |
| 282 |
|
| 283 |
/* ACCESS should check ACLs or it is lying. */ |
| 284 |
set_feature_default("DECC$ACL_ACCESS_CHECK" , ENABLE); |
| 285 |
|
| 286 |
/* We always want the new parse style */ |
| 287 |
set_feature_default ("DECC$ARGV_PARSE_STYLE" , ENABLE); |
| 288 |
|
| 289 |
/* Unless we are in POSIX compliant mode, we want the old POSIX root |
| 290 |
* enabled. |
| 291 |
*/ |
| 292 |
set_feature_default("DECC$DISABLE_POSIX_ROOT", DISABLE); |
| 293 |
|
| 294 |
/* EFS charset, means UTF-8 support */ |
| 295 |
/* VTF-7 support is controlled by a feature setting called UTF8 */ |
| 296 |
set_feature_default ("DECC$EFS_CHARSET" , ENABLE); |
| 297 |
set_feature_default ("DECC$EFS_CASE_PRESERVE" , ENABLE); |
| 298 |
|
| 299 |
|
| 300 |
/* Support timestamps when available */ |
| 301 |
set_feature_default ("DECC$EFS_FILE_TIMESTAMPS" , ENABLE); |
| 302 |
|
| 303 |
/* Cache environment varibles - performance improvements */ |
| 304 |
set_feature_default ("DECC$ENABLE_GETENV_CACHE" , ENABLE); |
| 305 |
|
| 306 |
/* Start out with new file attribute inheritance */ |
| 307 |
#ifdef __VAX |
| 308 |
set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", "2"); |
| 309 |
#else |
| 310 |
set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", 2); |
| 311 |
#endif |
| 312 |
|
| 313 |
/* Don't display trailing dot after files without type */ |
| 314 |
set_feature_default ("DECC$READDIR_DROPDOTNOTYPE" , ENABLE); |
| 315 |
|
| 316 |
/* For standard output channels buffer output until terminator */ |
| 317 |
/* Gets rid of output logs with single character lines in them. */ |
| 318 |
set_feature_default ("DECC$STDIO_CTX_EOL" , ENABLE); |
| 319 |
|
| 320 |
/* Fix mv aa.bb aa */ |
| 321 |
set_feature_default ("DECC$RENAME_NO_INHERIT" , ENABLE); |
| 322 |
|
| 323 |
if (use_unix_settings) { |
| 324 |
|
| 325 |
/* POSIX requires that open files be able to be removed */ |
| 326 |
set_feature_default ("DECC$ALLOW_REMOVE_OPEN_FILES", ENABLE); |
| 327 |
|
| 328 |
set_feature_default ("DECC$FILENAME_UNIX_ONLY" , ENABLE); |
| 329 |
/* FILENAME_UNIX_ONLY Implicitly sets |
| 330 |
decc$disable_to_vms_logname_translation */ |
| 331 |
|
| 332 |
set_feature_default ("DECC$FILE_PERMISSION_UNIX", ENABLE); |
| 333 |
|
| 334 |
/* For now this only with UNIX mode, applications can override |
| 335 |
* with out using a LIB$INITIALIZE setting. |
| 336 |
* This should be an application specific setting only enabled |
| 337 |
* if the application requires it. |
| 338 |
* Left here for now for backwards compatibility |
| 339 |
*/ |
| 340 |
set_feature_default ("DECC$FILE_SHARING" , ENABLE); |
| 341 |
|
| 342 |
set_feature_default ("DECC$FILE_OWNER_UNIX" , ENABLE); |
| 343 |
set_feature_default ("DECC$POSIX_SEEK_STREAM_FILE", ENABLE); |
| 344 |
|
| 345 |
} else { |
| 346 |
set_feature_default("DECC$FILENAME_UNIX_REPORT", ENABLE); |
| 347 |
} |
| 348 |
|
| 349 |
/* When reporting UNIX filenames, glob the same way */ |
| 350 |
set_feature_default ("DECC$GLOB_UNIX_STYLE" , ENABLE); |
| 351 |
|
| 352 |
/* The VMS version numbers on Unix filenames is incompatible with most */ |
| 353 |
/* ported packages. */ |
| 354 |
set_feature_default("DECC$FILENAME_UNIX_NO_VERSION", ENABLE); |
| 355 |
|
| 356 |
/* The VMS version numbers on Unix filenames is incompatible with most */ |
| 357 |
/* ported packages. */ |
| 358 |
set_feature_default("DECC$UNIX_PATH_BEFORE_LOGNAME", ENABLE); |
| 359 |
|
| 360 |
/* Set strtol to proper behavior */ |
| 361 |
set_feature_default("DECC$STRTOL_ERANGE", ENABLE); |
| 362 |
|
| 363 |
/* Pipe feature settings are longer needed with virtual memory pipe |
| 364 |
code. Programs that use pipe need to be converted to use the |
| 365 |
virtual memory pipe code, which effectively removes the hangs and |
| 366 |
left over temporary files. |
| 367 |
|
| 368 |
Comment left here to prevent regressions, as the larger pipe size |
| 369 |
actually hurts memory usage with the new algorithm. |
| 370 |
*/ |
| 371 |
/* do_not_set_default ("DECC$PIPE_BUFFER_SIZE" , 8192); */ |
| 372 |
|
| 373 |
|
| 374 |
/* Rather than remove this completely, a comment is left here to warn |
| 375 |
* someone from putting this bug back in. |
| 376 |
* |
| 377 |
* POSIX style UIDs require that the system administrator have set the |
| 378 |
* system up to use POSIX style UIDs and GIDs. And if they have done |
| 379 |
* so, then they should set the DECC$POSIX_STYLE_UID as a system wide |
| 380 |
* logical name. |
| 381 |
* |
| 382 |
* Setting them in a program will break all routines that expect GID/UID |
| 383 |
* stuff to work on systems set up by default with out mappings. |
| 384 |
* |
| 385 |
* Most utilities do not reference GID/UID values, so it took a while for |
| 386 |
* this bug to surface. |
| 387 |
*/ |
| 388 |
/* do_not_set_default ("DECC$POSIX_STYLE_UID" , TRUE); */ |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
/* GNV depends on SYS$POSIX_ROOT to be properly set. Since SYS$POSIX_ROOT |
| 393 |
* globally affects all C applications, SYS$POSIX_ROOT can not be set |
| 394 |
* anywhere that can be seen by other applications. |
| 395 |
* |
| 396 |
* So GNV$GNU is used instead, and SYS$POSIX_ROOT will be set in |
| 397 |
* in the process table in user mode to that value. |
| 398 |
* |
| 399 |
* Restriction: The system manager should not point GNV$GNU at |
| 400 |
* SYS$POSIX_ROOT, or anything that resolves to SYS$POSIX_ROOT. |
| 401 |
* |
| 402 |
*/ |
| 403 |
|
| 404 |
status = sys_trnlnm("GNV$GNU", |
| 405 |
gnv_posix_root, |
| 406 |
sizeof gnv_posix_root - 1); |
| 407 |
if ($VMS_STATUS_SUCCESS(status)) { |
| 408 |
status = sys_crelnm("SYS$POSIX_ROOT", "GNV$GNU:"); |
| 409 |
gnv_posix_root_found = 1; |
| 410 |
} |
| 411 |
|
| 412 |
/* GNV depends on BIN being set to GNV$GNU:[bin]. Since BIN |
| 413 |
* is not prefixed, and it affects everything globally, it needs to |
| 414 |
* be set here if it is not defined already. |
| 415 |
* If it is set already, assume that it is correct, rather than |
| 416 |
* trying to second guess the user. |
| 417 |
* If GNV$GNU is not defined, then define bin to be SYS$POSIX_ROOT. |
| 418 |
*/ |
| 419 |
|
| 420 |
status = sys_trnlnm("BIN", |
| 421 |
gnv_posix_root, |
| 422 |
sizeof gnv_posix_root - 1); |
| 423 |
if (!$VMS_STATUS_SUCCESS(status)) { |
| 424 |
if (gnv_posix_root_found) { |
| 425 |
status = sys_crelnm("BIN", "GNV$GNU:[BIN]"); |
| 426 |
} else { |
| 427 |
status = sys_crelnm("BIN", "SYS$POSIX_ROOT:[BIN]"); |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
} |
| 432 |
|
| 433 |
#pragma nostandard |
| 434 |
#pragma extern_model save |
| 435 |
#ifdef __VAX |
| 436 |
#pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long, nopic |
| 437 |
#else |
| 438 |
#pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long |
| 439 |
# if __INITIAL_POINTER_SIZE |
| 440 |
# pragma __pointer_size __save |
| 441 |
# pragma __pointer_size 32 |
| 442 |
# else |
| 443 |
# pragma __required_pointer_size __save |
| 444 |
# pragma __required_pointer_size 32 |
| 445 |
# endif |
| 446 |
#endif |
| 447 |
/* Set our contribution to the LIB$INITIALIZE array */ |
| 448 |
void (* const iniarray[])(void) = {set_coe, } ; |
| 449 |
#ifndef __VAX |
| 450 |
# if __INITIAL_POINTER_SIZE |
| 451 |
# pragma __pointer_size __restore |
| 452 |
# else |
| 453 |
# pragma __required_pointer_size __restore |
| 454 |
# endif |
| 455 |
#endif |
| 456 |
|
| 457 |
|
| 458 |
/* |
| 459 |
** Force a reference to LIB$INITIALIZE to ensure it |
| 460 |
** exists in the image. |
| 461 |
*/ |
| 462 |
int LIB$INITIALIZE(void); |
| 463 |
#ifdef __DECC |
| 464 |
#pragma extern_model strict_refdef |
| 465 |
#endif |
| 466 |
int lib_init_ref = (int) LIB$INITIALIZE; |
| 467 |
#ifdef __DECC |
| 468 |
#pragma extern_model restore |
| 469 |
#pragma standard |
| 470 |
#endif |