* InitProcessGlobals -- set MyProcPid, MyStartTime[stamp], random seeds * * Called early in the postmaster and every backend. */
| 3155 | * Called early in the postmaster and every backend. |
| 3156 | */ |
| 3157 | void |
| 3158 | InitProcessGlobals(void) |
| 3159 | { |
| 3160 | unsigned int rseed; |
| 3161 | |
| 3162 | MyProcPid = getpid(); |
| 3163 | MyStartTimestamp = GetCurrentTimestamp(); |
| 3164 | MyStartTime = timestamptz_to_time_t(MyStartTimestamp); |
| 3165 | |
| 3166 | /* |
| 3167 | * Set a different seed for random() in every process. We want something |
| 3168 | * unpredictable, so if possible, use high-quality random bits for the |
| 3169 | * seed. Otherwise, fall back to a seed based on timestamp and PID. |
| 3170 | */ |
| 3171 | if (!pg_strong_random(&rseed, sizeof(rseed))) |
| 3172 | { |
| 3173 | /* |
| 3174 | * Since PIDs and timestamps tend to change more frequently in their |
| 3175 | * least significant bits, shift the timestamp left to allow a larger |
| 3176 | * total number of seeds in a given time period. Since that would |
| 3177 | * leave only 20 bits of the timestamp that cycle every ~1 second, |
| 3178 | * also mix in some higher bits. |
| 3179 | */ |
| 3180 | rseed = ((uint64) MyProcPid) ^ |
| 3181 | ((uint64) MyStartTimestamp << 12) ^ |
| 3182 | ((uint64) MyStartTimestamp >> 20); |
| 3183 | } |
| 3184 | srandom(rseed); |
| 3185 | } |
| 3186 | |
| 3187 | |
| 3188 | /* |
no test coverage detected